home *** CD-ROM | disk | FTP | other *** search
- main() /* freopen.c -- illustrates use of freopen.c() */
- {FILE *fp;
- char name[20], c;
-
- printf("Filename: ");
- gets(name);
- clrerr(fp);
- if ((fp = fopen(name,"r")) == NULL)
- exit();
- while((c = getc(fp)) != EOF)
- putchar(c);
- fclose(fp);
-
- printf("Filename: "); /* here we go again */
- gets(name);
- clrerr(fp);
- if ((freopen(name,"r", fp)) == NULL) /* here we reuse file pointer */
- exit();
- while((c = getc(fp)) != EOF)
- putchar(c);
- fclose(fp);
-
- }