Long story short: You cannot assign to an array, it's not a modifiable lvalue. You need to define another pointer to hold the return value.
why is the variable line
considered type char[101]
and not type char *
In your case, line
is not considered to be of type char [101]
, it is indeed. In some of the cases, array decays down to a pointer to the first element in the array, but that does not change the fact that the array variable itself is of array type.
That said, you're overdoing it. You don't need to store the return value there. You can just check it against NULL
and get done with. fgets()
stores the scanned value in the line
array anyways. That's the whole point of passing line
(and it's size) in the first place.
That said, please see Why is “while ( !feof (file) )” always wrong?