M
Mike Wahler
Bonj said:Neither:
fp = fopen("xyz.txt", "r");
if (fp == NULL) {
...
}
is nearly right, but that's java style. Since your question is titled
'Recommended style', the correct style is
fp = fopen("xyz.txt", "r");
if (fp == NULL)
{
...
}
is correct, but if ... is only one line, then I prefer just
fp = fopen("xyz.txt", "r")
if(fp == NULL)
...
or better still
if(fopen("xyz.txt", "r") == NULL) ...
And now how will you refer to the stream?
They both will work, but if(!fp) is less explicit,
IMO it's quite explicit. A test for true/false (zero/nonzero).
as it's not actually a
boolean value you're testing, it's a returned handle, and you're testing
whether it's NULL or not.
You're testing whether 'fp', after being converted to 'int',
is zero or not.
-Mike