c中的文件IO函数,fopen,fgetc,fprintf,fclose /#include "stdio.h" int main() { FILE *fIn,*fOut; // 定义文件指针 fIn=fopen("testRead.txt","r"); //以只读方式打开,如果不能打开或文件不存在,返回fp会是NULL fOut=fopen("testWrite.txt","w"); //写文件 if(fIn!=NULL && fOut!=NULL) { char ch=fgetc(fIn); //顺序读取文件中的字符,碰到EOF终止 while(ch!=EOF) { //some code here printf("%c",ch); fprintf(fOut,"read from testRead.txt: %c/n",ch);//按照一定的格式输出 ch=fgetc(fIn); } } if(fIn!=NULL) fclose(fIn); if(fOut!=NULL) fclose(fOut); return 0; }