c primer plus 13 小知识点

c 程序自动打开3个文件,标准输入stdin,标准输出stdout和标准错误stderr输出。

FILE是stdio.h中定义的一种派生类型。指针并不指向实际的文件,而是指向一个关于文件的信息的数据包,其中包括文件I/O使用的缓冲区信息。

int fgetc ( FILE * stream ); 返回读取的字符。
Returns the character currently pointed by the internal file position indicator of 
the specified stream. The internal file position indicator is then advanced by one 
character to point to the next character.
fgetc and getc are equivalent, except that the latter one may be implemented as a macro.
------------------------------

int fputc ( int character, FILE * stream );
Writes a character to the stream and advances the position indicator.
The character is written at the current position of the stream as indicated by
the internal position indicator, which is then advanced one character.
-----------------------
exit()函数关闭所有打开的文件并终止程序。在stdlib.h头文件中有声明。
在最初调用的main()中使用return和调用exit()的效果相同。
但在不是最初调用的那一级,exit()会终止程序,但return将控制权移交给递归的前一级。
-----------------------

 

FILE * fopen ( const char * filename, const char * mode );
C string containing a file access modes. It can be:
"r"Open a file for reading. The file must exist.
"w"Create an empty file for writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file.
"a"Append to a file. Writing operations append data at the end of the file. The file is created if it does not exist.
"r+"Open a file for update both reading and writing. The file must exist.
"w+"Create an empty file for both reading and writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file.
"a+"

Open a file for reading and appending. All writing operations are performed at the end of the file, protecting the previous content to be overwritten. You can reposition (fseek, rewind) the internal pointer to anywhere in the file for reading, but writing operations will move it back to the end of file. The file is created if it does not exist. 

上面的模式是以文本模式打开文件,再加上'b',成为:"rb", "wb", "ab", "r+b", "w+b", "a+b","rb+", "wb+", "ab+",这些代表用二进制模式打开文件。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值