哥哥姐姐们帮我看下这个代码对不对呀,为啥我明明新建了文档,但是结果却总是说没办法打开呢

不瘦100斤不改网名 2019-12-24 10:49:53
谢谢 #include<stdio.h> #include<stdlib.h> void main() { FILE*fp; char ch,filename[20]; printf("please input the filename you want to write:"); scanf("%s",filename); if( !(fp==fopen(filename,"wt+")) ); { printf("cannot open the file!\n"); exit(0); } printf("please input the sentences you want to write:"); ch=getchar(); ch=getchar(); while( ch!=EOF ) { fputc(ch,fp); ch=getchar(); } fclose(fp); }
...全文
105 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
引用 3 楼 it_xiangqiang的回复:
希望对你有帮助:https://blog.csdn.net/it_xiangqiang/category_10581430.html 希望对你有帮助:https://blog.csdn.net/it_xiangqiang/category_10768339.html
谢谢大佬真的网站的模板怎么做不
源代码大师 2021-05-06
  • 打赏
  • 举报
回复
希望对你有帮助:https://blog.csdn.net/it_xiangqiang/category_10581430.html 希望对你有帮助:https://blog.csdn.net/it_xiangqiang/category_10768339.html
  • 打赏
  • 举报
回复
引用 1 楼 自信男孩的回复:
#include<stdio.h>
#include<stdlib.h>

//void main()
int main()
{
FILE*fp;
char filename[20];
int ch; //定义为int,这样才能与EOF比较
printf("please input the filename you want to write:");
scanf("%s",filename);
//if( !(fp==fopen(filename,"wt+")) ); //为啥多一个分号, 为啥用==
if(!(fp=fopen(filename,"wt+")))
{
printf("cannot open the file!\n");
exit(0);
}
printf("please input the sentences you want to write:");
ch = getchar();
ch = getchar();
while( ch!=EOF )
{
fputc(ch,fp);
ch=getchar();
}
fclose(fp);

return 0;
}

供参考~
谢谢~~
自信男孩 2019-12-25
  • 打赏
  • 举报
回复
#include<stdio.h>
#include<stdlib.h>

//void main()
int main()
{
FILE*fp;
char filename[20];
int ch; //定义为int,这样才能与EOF比较
printf("please input the filename you want to write:");
scanf("%s",filename);
//if( !(fp==fopen(filename,"wt+")) ); //为啥多一个分号, 为啥用==
if(!(fp=fopen(filename,"wt+")))
{
printf("cannot open the file!\n");
exit(0);
}
printf("please input the sentences you want to write:");
ch = getchar();
ch = getchar();
while( ch!=EOF )
{
fputc(ch,fp);
ch=getchar();
}
fclose(fp);

return 0;
}

供参考~

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧