A part of this C code is bugging me, and I can't see what I am doing wrong. I am not trying to get someone to write the complete code, since this is my homework assignment, but I would really like to know what am I doing wrong here. So this is a part of main:
FILE *fp,*fd;
fp=fopen("test1.txt","r");
if (fp==NULL)
return -1;
fd=fopen("test2.txt","w");
if (fd==NULL)
return -2;
while (fp != EOF){
fread(fd,1,10,fp);
}
//read_copy(fp,fd);
fclose(fp);
fclose(fd);
return 0;
And I can't seem to figure out why it doesn't work. With while written like this, it goes into an infinite loop. If I try to put a fscanf()
in while, it gives me seg fault
. So what am I doing wrong?
Thx!