将source.txt 文本文件中的内容复制到dest.txt文本文件中,再将dest.txt文件中的内容读出显示到屏幕. 代码是: #include #include int main(void) { FILE *fp,*fout; char ch[80]; if((fp=fopen("source.txt","w"))==NULL) { printf("Cannot create the output file!\n"); exit(1); } while((ch[80]=getchar())!='\n') fputc(ch[80], fp); fclose(fp); if((fp=fopen("source.txt","r"))==NULL) { printf("Cannot open this file!\n"); exit(1); } if((fout=fopen("dest.txt","w"))==NULL) { printf("Cannot create the output file!\n"); exit(1); } while(fgets(ch,80,fp)!=NULL) fputs(ch,fout); fclose(fp); fclose(fout); printf("\n"); return 0; } 为什么可以输入但却不可以输出呢?
ch[80]=getchar()这是干啥,你ch一共就申请了80个字节大小,ch[80]直接越界了
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632