First of all, your test:
fgets(str, LINE_LEN, stdin);
[...]
if (str==NULL) {
goto errorfgets;
}
is wrong. The str
parameter is passed by value and cannot be modified by fgets()
. Instead, you should be checking the value returned by fgets()
(returns NULL
on EOF or error).
Regarding your specific question: fgets()
does not "return" feof
or ferror
. Both feof()
and ferror()
are actually functions (see the man pages). You would use this as follows:
if (!fgets(str, LINE_LEN, stdin)) {
/* fgets returns NULL on EOF and error; let's see what happened */
if (ferror(stdin)) {
/* handle error */
} else {
/* handle EOF */
}
}