文件操作剖析.ppt

#include “stdio.h” main() { char c; FILE *fp; if((fp=fopen(“tt.txt”, “r”))==NULL) { printf(“error!\n”): exit(0); } c=fgetc(fp); while(c!=EOF) { putchar(c); c=fgetc(fp); } fclose(fp); } 例:从文件tt.txt中顺序读取字符并显示出来。 #include “stdio.h” main() { char c; FILE *fp; if((fp=fopen(“tt.txt”, “r”))==NULL) { printf(“error!\n”): exit(0); } c=fgetc(fp); while(c!=EOF) { putchar(c); c=fgetc(fp); } fclose(fp); } 例:从文件tt.txt中顺序读取字符并显示出来。 三、文件的数据块的读写—fread和 fwrite函数 函数调用成功返回count的值,否则返回-1。 fwrite()函数的功能: 将内存中的一组数据写到fp所指向的文件中。

文档评论(0)

1亿VIP精品文档

相关文档