C语言File文件操作函数学习
(禁止转载)
(content from 《C Primer Plus, Fifth Edition》 By Stephen Prata)
· Functions:
fopen(), getc(), putc(), exit(), fclose()
fprintf(), fscanf(), fgets(), fputs()
fread(), fwrite()
fopen()
该函数可以用来打开一个文件,同时可以根据第二参数决定对该文件的操作类型。
具体格式例如:
FILE *fp;
fp=fopen(“test.txt”,”w+x”); //加x后,若文件存在,则打开失败,防止改写原文件
"r" |
read: Open file for input operations. The file must exist. |
"w" |
write: Create an empty file for output operations. If a file with the same name already exists, its contents are discarded and the file is treated as a new empty file. |
"a" |
append: Open file for output at the end of a file. Output operations always write data at the end of the file, expanding it. Repositioning operations (fseek, |