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 }
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 }
fputc(int ch,FILE *fp)和fgetc(FILE *fp)的用法
原文:https://www.cnblogs.com/renhao1024/p/12009557.html