求助!!文件读写总出错。
程序代码:
#include<stdio.h> FILE*FileOpen(char *filename,char*mode) /*打开文件的函数*/ { FILE*fp; fp=fopen(filename,mode); if(fp==NULL) printf("open file failed"); else return (fp); } void FileCopy(FILE*file_in,FILE*file_out) /*复制文件内容的函数*/ { char c; while((c=fgetc(file_in))!=EOF) fputc(c,file_out); } int main() { FILE *fp1,*fp2; char s[20],c; printf("please input the file name:"); gets(s); fp1=FileOpen(s,"r"); fp2=FileOpen("fp2","w"); FileCopy(fp1,fp2); while((c=fgetc(fp1)!=EOF)) /*将文件中小写想字母转换成大写后输出*/ { if(c>='a'&&c<='z') printf("%c",c-32); printf("%c",c); } fclose(fp1); fclose(fp2); return 0; } 运行情况: please input the file name:File1 open file failedPress any key to continue 还弹出一个窗口:03.exe遇到问题需要关闭。