# Thread: a simple question

1. ## a simple question

say i have a statement:

Code:
`while (c = fgetc(in) != EOF) { .... }`
where in is some file pointer. will "c=fgetc(in)" evaluate to a true/false expression? or will that expression reflect the value of fgetc(in)? i read somewhere that something like:
Code:
`a = b = c = d = 0;`
only works when you're using a zero. is this right?

2. will "c=fgetc(in)" evaluate to a true/false expression? or will that expression reflect the value of fgetc(in)?
The expression ends up comparing the value stored in 'c' with the EOF check.

Basicly it's like doing:
c = fgetc( in );
if( c != EOF ) ...

i read somewhere that something like:

code:
a = b = c = d = 0;

only works when you're using a zero. is this right?
Incorrect.

This is a simple assignment. Take the right most value, assign it to the item to the left. Take the value in d, assign it to c, take the value of c...

The end result is that whatever is on the right most side, everything to the left of it will be set to that value (whatever that value is).

Quzah.

3. k, thanks

4. abt what i should reply

5. Originally posted by hemalatha
abt what i should reply
hhhmmmm !!

6. > while (c = fgetc(in) != EOF) { .... }
Remember your precedence rules

As written, this is
while ( c = (fgetc(in) != EOF) ) { .... }
Which will loop through the file until EOF, but c will always be 1 (ie true, because the result of fgetc was not EOF)

Normally, you want to do this
while ( (c = fgetc(in)) != EOF ) { .... }

Popular pages Recent additions