home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c025 / 1.ddi / FREOPEN.C < prev    next >
Encoding:
Text File  |  1985-01-24  |  481 b   |  24 lines

  1. main()    /* freopen.c -- illustrates use of freopen.c() */
  2. {FILE *fp;
  3. char name[20], c;
  4.  
  5.     printf("Filename: ");
  6.     gets(name);
  7.     clrerr(fp);
  8.     if ((fp = fopen(name,"r")) == NULL)
  9.         exit();
  10.     while((c = getc(fp)) != EOF)
  11.         putchar(c);
  12.     fclose(fp);
  13.  
  14.     printf("Filename: ");    /* here we go again */
  15.     gets(name);
  16.     clrerr(fp);
  17.    if ((freopen(name,"r", fp)) == NULL) /* here we reuse file pointer */
  18.       exit();
  19.     while((c = getc(fp)) != EOF)
  20.         putchar(c);
  21.     fclose(fp);
  22.  
  23. }
  24.