C
Cross
Hello
I am using the following code to check fscanf() error value.
----------------------------------
#include <stdio.h>
int main(){
char arr[6];
int a;
FILE *fs=fopen("lessread.in", "r");
if(fs){
a = fscanf(fs, "%5s", arr);
printf("%s %d\n", arr, a);
}else{
fprintf(stderr, "read error.\n");
}
return 0;
}
-----------------------------------------
The contents of the file are:
---------------------------------
les
---------------------------------
The manual said that if end-of-file is reached before specified characters are
read, EOF is returned. However, my output is:
---------------------------------------
les 1
---------------------------------------
My actual motive: when I am using fscanf() to read a file with the format
sequence "%[^c]" where c is some character, how do I know whether EOF has been
reached or the read was successful.
Regards,
Cross
I am using the following code to check fscanf() error value.
----------------------------------
#include <stdio.h>
int main(){
char arr[6];
int a;
FILE *fs=fopen("lessread.in", "r");
if(fs){
a = fscanf(fs, "%5s", arr);
printf("%s %d\n", arr, a);
}else{
fprintf(stderr, "read error.\n");
}
return 0;
}
-----------------------------------------
The contents of the file are:
---------------------------------
les
---------------------------------
The manual said that if end-of-file is reached before specified characters are
read, EOF is returned. However, my output is:
---------------------------------------
les 1
---------------------------------------
My actual motive: when I am using fscanf() to read a file with the format
sequence "%[^c]" where c is some character, how do I know whether EOF has been
reached or the read was successful.
Regards,
Cross