
C语言:将两个文件的内容合并生成一个新文件
我编了这个程序,编译通过了,但是运行的时候提示"Ox004010cb"指令引用的"Ox0000000c"内存。该内存不能为"read"。一般这种情况是事先没对指针赋值吗?...
我编了这个程序,编译通过了,但是运行的时候提示"Ox004010cb"指令引用的"Ox0000000c"内存。该内存不能为"read"。一般这种情况是事先没对指针赋值吗?但是我好像都赋了值的。
到底是什么原因呢?
#include <stdio.h>
#include <stdlib.h>
void main()
{
char ch[100],*p=ch;
FILE *fa,*fb,*fc;
if((fa=fopen("A.txt","r"))=NULL)
{
printf("cannot open file\n");
exit(0);
}
if((fb=fopen("B.txt","r"))==NULL)
{
printf("cannot open file\n");
exit(0);
}
if((fc=fopen("C.txt","w"))==NULL)
{
printf("cannot open file\n");
exit(0);
}
while(!feof(fa))
*p++=fgetc(fa);
while(!feof(fb))
*p++=fgetc(fb);
*p='\0';
fputs(ch,fc);
fclose(fa);
fclose(fb);
fclose(fc);
} 展开
到底是什么原因呢?
#include <stdio.h>
#include <stdlib.h>
void main()
{
char ch[100],*p=ch;
FILE *fa,*fb,*fc;
if((fa=fopen("A.txt","r"))=NULL)
{
printf("cannot open file\n");
exit(0);
}
if((fb=fopen("B.txt","r"))==NULL)
{
printf("cannot open file\n");
exit(0);
}
if((fc=fopen("C.txt","w"))==NULL)
{
printf("cannot open file\n");
exit(0);
}
while(!feof(fa))
*p++=fgetc(fa);
while(!feof(fb))
*p++=fgetc(fb);
*p='\0';
fputs(ch,fc);
fclose(fa);
fclose(fb);
fclose(fc);
} 展开
3个回答
展开全部
if((fa=fopen("A.txt","r"))=NULL)
这里错了,把=NULL改成==NULL
if((fa=fopen("A.txt","r"))==NULL)
这里错了,把=NULL改成==NULL
if((fa=fopen("A.txt","r"))==NULL)
展开全部
是不是文件内容太多了,吧字符串数组定义大一点看看。
char ch[100],*p=ch;
改为char ch[10000],*p=ch;
char ch[100],*p=ch;
改为char ch[10000],*p=ch;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
if((fa=fopen("A.txt","r"))=NULL)
右边的是==,你写成了=
右边的是==,你写成了=
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询