1 #include <stdio.h>
 2 #include <stdlib.h>
 3 
 4 int main(void)
 5 {
 6     FILE *fp;
 7     /* char arr[100]; */
 8 
 9     //write sth to T.txt
10     fp = fopen("T.txt","w");
11     if(fp == NULL)
12     {
13         puts("File open failed.");
14         exit(EXIT_FAILURE);
15     }
16     fprintf(fp,"%s","How are you doing?\n");
17     fclose(fp);
18 
19     //output T.txt
20     fp = fopen("T.txt","r");
21     if(fp == NULL)
22     {
23         puts("File open failed.");
24         exit(EXIT_FAILURE);
25     }
26     /* if(fgets(arr,100,fp) != NULL)
27         puts(arr); */
28     for(;;)
29     {
30         if(feof(fp))
31             break;
32         putchar(getc(fp));
33     }
34     fclose(fp);
35             
36     return 0;
37 }
View Code