"Taran" <> writes:
[...]
>> if (fp=NULL)
>
> You wanted to compare fp to NULL but actually you are assigning NULL to
> fp. Since fp is assigned to Null (0), 'if' fails and skips the if
> block.
[...]
> Instead the comparisons should be:
> if (fd==NULL)
>
> A better programming practice
> if(NULL==fd)
> This way even if you miss the second = for equality, you do not
> inadverently assign NULL to a pointer which is a bug and is easier to
> find in large projects. (ptr=NULL) is difficult to find.
That's one solution, but reasonable people differ on whether reversing
the operands of "==" is good style or a horribly ugly crutch.
Personally, I find it ugly, and it makes the code more difficult to
read; "fd==NULL" just looks more natural to me that "NULL==fd". I
know that some people don't have a problem with it.
As a programmer, you'll just need to be able to cope with both styles,
even if one of them annoys you.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.