Newsgroups: comp.lang.c
Path: utzoo!henry
From: henry@utzoo.uucp (Henry Spencer)
Subject: Re: TO C OR NOT TO *C
Message-ID: <1989Oct16.172249.18387@utzoo.uucp>
Organization: U of Toronto Zoology
References: <16107@nswitgould.cs.uts.oz>
Date: Mon, 16 Oct 89 17:22:49 GMT

In article <16107@nswitgould.cs.uts.oz> jon_hogan-doran%713.600@fidogate.fido.oz (Jon Hogan-doran) writes:
>... it said (something like this) that getc(fd)
>returned an int value .. and yet later on he gave an example
>(something like this):
> 
>char ch;
>ch=getc(ttyd);

Barring unusual situations, his example is simply wrong.  getc does return
an int.  The value will fit in a char except in one important case:  EOF.
Unless you have reason to be *absolutely certain* that end-of-file will
not occur when attempting to read that character, the result of getc should
*never* be assigned to a char without first testing to see if it is equal
to EOF.  That usually means assigning it to an int first, so you can test
the value and then use it.
-- 
A bit of tolerance is worth a  |     Henry Spencer at U of Toronto Zoology
megabyte of flaming.           | uunet!attcan!utzoo!henry henry@zoo.toronto.edu
