Results 1 to 3 of 3
main(){
FILE *fp;
char a;
fp=fopen("giis.txt","r");
if(fp==NULL){
printf("\nFile open error");
return -1;
}
fscanf(fp,"%c",&a)
while(a!=EOF){
printf("%c",a);
fscanf(fp,"%c",&a)
}
close(fp);
}
Above prints the contents of file and goes into infinite ...
- 02-19-2009 #1
C program -problem with EOF
Above prints the contents of file and goes into infinite loop.main(){
FILE *fp;
char a;
fp=fopen("giis.txt","r");
if(fp==NULL){
printf("\nFile open error");
return -1;
}
fscanf(fp,"%c",&a)
while(a!=EOF){
printf("%c",a);
fscanf(fp,"%c",&a)
}
close(fp);
}
It's not detecting the end of file.
What's the probllem and How to solve this?- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 02-19-2009 #2
fscanf returns EOF when it's reached. It does not put this into the variable "a".
Debian GNU/Linux -- You know you want it.
- 02-19-2009 #3
Thanks GNU-Fan
- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------


Reply With Quote