[TUHS] v7 K&R C
Clem Cole
clemc at ccc.com
Sat May 16 06:24:47 AEST 2020
I suspect we are saying the same thing. C is defined as an int (as Larry
also showed), not an unsigned char (and frankly if you had done that, most
modern compilers will give you a warning). IIRC you are correct that the
Ritchie compiler would not catch that error.
But, the truth is I know few C (experienced) programmers that would define
c as anything but an int; particularly in the modern era with compiler
warnings as good as they are.
Clem
On Fri, May 15, 2020 at 4:18 PM <ron at ronnatalie.com> wrote:
> EOF is defined to be -1.
>
> getchar() returns int, but c is a unsigned char, the value of (c =
> getchar()) will be 255. This will never compare equal to -1.
>
>
>
>
>
>
>
> Ron,
>
>
>
> Hmmm... getchar/getc are defined as returning int in the man page and C is
> traditionally defined as an int in this code..
>
>
>
> 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 */
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://minnie.tuhs.org/pipermail/tuhs/attachments/20200515/23312489/attachment.htm>
More information about the TUHS
mailing list