Re: Wierd output instead of 0s and 1s
From: Joona I Palaste (palaste_at_cc.helsinki.fi)
Date: 03/01/04
- Next message: Martin Dickopp: "Re: What is sequence point ?"
- Previous message: Martin Dickopp: "Re: cast in memcpy()"
- In reply to: Joona I Palaste: "Re: Wierd output instead of 0s and 1s"
- Next in thread: Sathyaish: "Re: Wierd output instead of 0s and 1s"
- Reply: Sathyaish: "Re: Wierd output instead of 0s and 1s"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 1 Mar 2004 10:43:25 GMT
Joona I Palaste <palaste@cc.helsinki.fi> scribbled the following:
> Sathyaish <VisualBasicLearner@yahoo.com> scribbled the following:
>> #include <stdio.h>
>> /*This program is made to check that leaving the brackets around the
>> epxression (c=getchar()) in
>> the statement while ((c=getchar()) !=EOF) produces a boolean output in
>> C which would either be
>> 0 (false) or 1 (true). This would happen because the relational
>> operator != has precedence over the assignment
>> operator =.
>> */
>> void main()
> Non-standard form of main(). Better would be int main(void).
>> {
>> int c;
>> while (c=getchar() != EOF) putchar(c);
This loop is printing the character whose code is 1 (true value)
as long as getchar()!=EOF. Note that 1 and '1' are not the same thing.
>> /* Surprisingly, it doesn't produce zeros while I type; rather it
>> produces some wierd characters that look
>> half like zeros and half like smileys. And doing a Ctrl+Z, which I
>> thought was the substitute for EOF does
>> not produce a 1 (true value) */
> Note that if c==EOF, the putchar(c) is never called, so your program
> will never print a 1 (true value) for any input.
>> }
I meant, of course, "if getchar()==EOF and therefore c==0, the
putchar(c) is never called, so your program will never print a 0 (false
value) for any input."
-- /-- Joona Palaste (palaste@cc.helsinki.fi) ------------- Finland --------\ \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/ "Outside of a dog, a book is a man's best friend. Inside a dog, it's too dark to read anyway." - Groucho Marx
- Next message: Martin Dickopp: "Re: What is sequence point ?"
- Previous message: Martin Dickopp: "Re: cast in memcpy()"
- In reply to: Joona I Palaste: "Re: Wierd output instead of 0s and 1s"
- Next in thread: Sathyaish: "Re: Wierd output instead of 0s and 1s"
- Reply: Sathyaish: "Re: Wierd output instead of 0s and 1s"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]