[C] rewind函数 →→→→→进入此内容的聊天室

来自 , 2020-02-29, 写在 C, 查看 102 次.
URL http://www.code666.cn/view/50525975
  1. /* 使用rewind函数 */
  2. #include <stdio.h>
  3. #define SIZE 200
  4.  
  5. int main(void) {
  6.         FILE * fp = NULL;
  7.         int i = 0;
  8.         char ch;
  9.  
  10.         fp = fopen("test.txt", "r");
  11.         if (NULL == fp) {
  12.                 printf("Can't open file \"test.txt\"");
  13.                 return -1;
  14.         }
  15.  
  16.         /* 第一次输出文件内容 */
  17.         fprintf(stdout, "First time:\n");
  18.         ch = fgetc(fp);
  19.         while (!feof(fp)) {
  20.                 fputc(ch, stdout);
  21.                 ch = fgetc(fp);
  22.         }
  23.  
  24.                 /* 第二次输出文件内容 */
  25.         fprintf(stdout, "Second time:\n");
  26.         rewind(fp);
  27.         ch = fgetc(fp);
  28.         while (!feof(fp)) {
  29.                 fputc(ch, stdout);
  30.                 ch = fgetc(fp);
  31.         }
  32.  
  33.         fclose(fp);
  34.         fp = NULL;
  35.  
  36.         return 0;
  37. }
  38.  

回复 "rewind函数"

这儿你可以回复上面这条便签

captcha