1.fgetc(FILE *fp)
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 int main()
5 {
6 FILE *fp;
7 int ch;
8 if((fp=fopen("demo.txt","r"))==NULL)
9 {
10 printf("Failure to open demo.txt!\n");
11 exit(0);
12 }
13 while((ch=fgetc(fp))!= EOF)
14 putchar(ch);
15 fclose(fp);
16 return 0;
17 }
2.fputc(int ch,FILE *fp)
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 int main()
5 {
6 FILE *fp;
7 int ch;
8 if((fp=fopen("demo.txt","w"))==NULL)
9 {
10 printf("Failure to open demo.txt!\n");
11 exit(0);
12 }
13 while((ch=getchar())!= '\n')
14 fputc(ch,fp);
15 fclose(fp);
16 return 0;
17 }