fputc(int ch,FILE *fp)和fgetc(FILE *fp)的用法

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 }
posted @ 2019-12-09 10:30  迪迦奥特快  阅读(1356)  评论(0编辑  收藏  举报