Mail Archives: djgpp/1998/02/10/23:16:00
Charbel Sadaka wrote:
>
> Hi ,
> I'm Charbel (or just Charlie if you prefer), and would really appreciate
> it if you could solve this simple problem I have.
>
> I've downloaded the c compiler from delorie.com for win95(ieDOS)and have
> no problems with it except that I've tried writing a simple program to
> read from the stdin and count the number of characters in it using the
> following code:
> while (ch=getchar( ) != EOF) {
> count++
> }
Besides the fact that EOF is control Z in dos, not control D, this code
won't work because the != operator has higher precedence than the =
(assignment) operator. So what the code in the while parentheses says
is "if you entered EOF then store false in ch, else store true". You
can fix this using parentheses: (ch = getchar()) != EOF)
-Eamon Walsh
- Raw text -