#include<stdio.h>
#include<stdlib.h>
int main(){
FILE* fp;
char c;
char filename[40] = {};
printf("filename:");
gets_s(filename);
if ( (fp = fopen("filename", "w"))== NULL) {
printf("can't open the %s\n", filename);
exit(0);
}
while ((c = getchar()) != EOF) {
fputc(c, fp);
}
fclose(fp);
printf("outfile:\n");
fp = fopen("filename", "r");
while ((c = fgetc(fp)) != EOF) {
putchar(c);
}
fclose(fp);
return 0;
}
文件操作应用:利用fputc和fgetc函数建立一个文本文件,并显示文件中的内容。
最新推荐文章于 2024-09-01 02:07:48 发布