/* 使用rewind函数 */ #include #define SIZE 200 int main(void) { FILE * fp = NULL; int i = 0; char ch; fp = fopen("test.txt", "r"); if (NULL == fp) { printf("Can't open file \"test.txt\""); return -1; } /* 第一次输出文件内容 */ fprintf(stdout, "First time:\n"); ch = fgetc(fp); while (!feof(fp)) { fputc(ch, stdout); ch = fgetc(fp); } /* 第二次输出文件内容 */ fprintf(stdout, "Second time:\n"); rewind(fp); ch = fgetc(fp); while (!feof(fp)) { fputc(ch, stdout); ch = fgetc(fp); } fclose(fp); fp = NULL; return 0; }