c语言 文件操作 报错 file1.txt 中的句子分行输出到 file2.txt

#include<stdio.h>#include<conio.h>#include<stdlib.h>main(){FILE*pt,*tyq;chara[30],ch;... #include<stdio.h>
#include<conio.h>
#include<stdlib.h>
main()
{
FILE *pt,*tyq;
char a[30],ch;
int i=0,j;
if((pt=fopen("file1.txt","a"))==NULL)
{
printf("sorry\n");
getch();
exit(1);
}
if((pt=fopen("file2.txt","a"))==NULL)
{
printf("sorry\n");
getch();
exit(1);
}

while((ch=getc(pt))!=EOF)
{
a[i++]=ch;
while((ch=fgetc(pt))!=".")
a[i++]=ch;

{
for(j=0;j<i;j++)
fputc(a[j],tyq);
fputc('.',tyq);
fputc('\n',tyq);
}

}

fclose(pt);
fclose(tyq);
}
展开
 我来答
百度网友7e370dd
推荐于2016-10-08 · 超过28用户采纳过TA的回答
知道答主
回答量:69
采纳率:100%
帮助的人:32.5万
展开全部
你把打开file1和file2的顺序变一下,if((pt=fopen("file2.txt","a"))==NULL)中的pt应该是typ
更多追问追答
追问
什么意思
追答
if((pt=fopen("file2.txt","a"))==NULL)
{
printf("sorry\n");
getch();
exit(1);
}
if((pt=fopen("file1.txt","a"))==NULL)
{
printf("sorry\n");
getch();
exit(1);
}
改成这样,要是还不行的话,就把if((pt=fopen("file2.txt","a"))==NULL)中的pt修改成typ

还有为啥你在fopen错误还要getch()呢?没有看懂
还有在 FILE *pt,*tyq定义是要先=NULL才行,关闭以后也让pt,typ=NULL
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式