K
Kobu
My question is about EOF (which is (int)-1 on the
implementation I use). Type char on my implementation
is 'signed' too.
How is it that the input library functions that return
EOF can be used properly if something like ASCII 255
is read from the input file? 255 would be returned as -1,
and would be compared against EOF and cause problems.
What's the point of declaring a int to hold the return
value from these functions, when a char(on my implementation)
can represent a -1(EOF on my representation) also?
Example;
char c_char;
while( (c_char = getchar()) != EOF )
{ /* something */ }
will work just as *badly* as:
int c_int;
while( (c_int= getchar()) != EOF )
{ /* something */ }
I'm not complaining about the AMBIGUITY of
(int)EOF vs.(int)(Ascii 255 returned as -1)
but wondering why people suggent capturing the
return value from functions like getchar into
an int, when the int doesn't help us get rid
of this ambiguous case?
I've tried to research this to death and wrap my
mind around a possible answer, but I have failed
miserably. I need someone to help me turn on the
flickering lightbulb.
Much thanks in advance
implementation I use). Type char on my implementation
is 'signed' too.
How is it that the input library functions that return
EOF can be used properly if something like ASCII 255
is read from the input file? 255 would be returned as -1,
and would be compared against EOF and cause problems.
What's the point of declaring a int to hold the return
value from these functions, when a char(on my implementation)
can represent a -1(EOF on my representation) also?
Example;
char c_char;
while( (c_char = getchar()) != EOF )
{ /* something */ }
will work just as *badly* as:
int c_int;
while( (c_int= getchar()) != EOF )
{ /* something */ }
I'm not complaining about the AMBIGUITY of
(int)EOF vs.(int)(Ascii 255 returned as -1)
but wondering why people suggent capturing the
return value from functions like getchar into
an int, when the int doesn't help us get rid
of this ambiguous case?
I've tried to research this to death and wrap my
mind around a possible answer, but I have failed
miserably. I need someone to help me turn on the
flickering lightbulb.
Much thanks in advance