On Fri, May 15, 2020 at 4:02 PM
<ron(a)ronnatalie.com> wrote:
Unfortunately, if c is char on a machine with unsigned chars, or it’s of
type unsigned char, the EOF will never be detected.
- while ((c = getchar()) != EOF) if (c == '\n') { /* entire record is now
there */
The function prototype for getchar() is: int getchar(void);
It returns an int, not a char. In all likelihood this is specifically
*because* EOF is defined as -1. The above code works fine if c is an
int. One always has to be very careful when doing a typecast of a
function return value.
-Paul W.