秘密之狐
2021-01-17 17:00这两个一样的代码对同一个文件咋一个打的开一个打不开嘞
这是网上大大的代码
#include <stdio.h>
int main()
{
FILE *fp;
char ch,filename[20];
printf("Please input your filename:");
scanf("%s",filename);
if(!(fp=fopen(filename,"w")))
{
printf("Can not open %s\n",filename);
}
else
{
printf("Please input the sentences you write:");
ch=getchar();
ch=getchar();
while(ch!=EOF)
{
fputc(ch,fp);
ch=getchar();
}
fclose(fp);
}
if(!(fp=fopen(filename,"r")))
{
printf("Can not open %s\n",filename);
}
else
{
printf("The content of %s is:",filename);
while(!feof(fp))
{
ch=fgetc(fp);
putchar(ch);
}
printf("\n");
fclose(fp);
}
return 0;
}
这是萌新的我的代码
#include<stdio.h>
#include<stdlib.h>
int main ()
{
FILE *fp;
char ch,filename[20];
printf("please input the filename you want to write:");
scanf("%s",filename);
if(!(fp=fopen(filename,"w")));
{printf("can not open the file");
exit(0);
}
printf("please input the sentences you want:");
ch=getchar();
ch=getchar();
while(ch!=EOF)
{
fputc(ch,fp);
ch=getchar();
}
fclose(fp);
}
感觉明明是一样的啊
- 点赞
- 回答
- 收藏
- 复制链接分享
3条回答
为你推荐
- hibernate 同一个类中多对一,一对多,不会用,请指教,讲解一下,最好是告诉我如何遍历
- hibernate
- 0个回答
- eclipse双击取消断点不起作用
- java
- eclipse
- 5个回答