The above was written by RjY <
[email protected]>. Rafael, please don't delete
attribution lines for quoted text.
And please don't top-post. See the following for more information:
http://www.caliburn.nl/topposting.html
http://www.cpax.org.uk/prg/writings/topposting.php
A still better style is:
while (fread(&teu, sizeof teu, 1, fp)) {
printf(......);
}
since C considers any non-zero integer to be true, and 0 to be false.
Yes, it does, and your revised code is valid, but I fail to see how
it's better style.
For one thing, just because C allows you to omit an explicit
comparison doesn't mean it's a good idea. Opinions differ on this,
but personally I prefer to use an explicit comparison unless the value
being tested is "boolean". The value returned by fread is a count,
not a true/false status, so I find an explicit comparison clearer.
Second, you've changed the meaning of the code. This:
fread(...)
is true if fread returns any non-zero value, whereas this:
fread(...) == 1
is true only if fread returns 1. As it happens, fread with the value
1 as its third argument can only return 1, so it doesn't matter in
this case. But consider what would happen if, rather than fread, you
were using fscanf, which can return either the number of items scanned
(possibly 0) or EOF.