【C语言程序设计第四版】练习12-5
写字符并验证
#include <stdio.h> #include <stdlib.h> #define MAXN 300 int main(void){ FILE *fp; char ch; char string[MAXN]; gets(string); if ((fp=fopen("f3.txt", "w+")) == NULL) { printf("File open errpr!\n"); exit(0); } fputs(string, fp); rewind(fp); while ((ch=fgetc(fp))!=EOF) { putchar(ch); } if ((fclose(fp))) { printf("Can not close the file!\n"); exit(0); } return 0; }