[TUHS] v7 K&R C
    Paul Winalski 
    paul.winalski at gmail.com
       
    Sun May 17 02:28:01 AEST 2020
    
    
  
> On Fri, May 15, 2020 at 4:02 PM <ron at 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.
    
    
More information about the TUHS
mailing list