"Keith Thompson" <kst-u@[EMAIL PROTECTED]
> wrote in message
news:87bq3nys73.fsf@[EMAIL PROTECTED]
> The syntax of a while statement is:
>
> while ( expression ) statement
>
> Note that that's a *single* statement. If you want the body to be
> multiple statements, you need to wrap them in braces to create a
> compound statement,
I see.
which is itself as single statement. (The same
> thing applies to if statements; you correctly used braces for those,
I think braces are required with if.
> so I don't know why the while loop was such a problem.)
>
> The code I quoted is equivalent to this:
>
> [...]
> while (a != EOF)
> a = fgetc(ifp);
> fputc(a, ofp);
> printf("done\n");
> return 0;
> }
>
> With proper indentation, you can see that the while controls only a
> single statement, ``a = fgetc(ifp);''. The fputc call will occur
> exactly once, after the while loop terminates. I can't be certain,
> but I *think* you wanted both the fgetc and fputc calls to be in the
> body of the loop. To do that, you need braces:
>
> [...]
> while (a != EOF) {
> a = fgetc(ifp);
> fputc(a, ofp);
> }
> printf("done\n");
> return 0;
> }
>
> In my opinion, it's a good habit always to use braces even if you only
> want only a single statement in the body. It makes the code more
> consistent and easier to maintain if you later want to add a second
> statement. (Others will disagree.)
>
> Judicious use of whitespace, especially around operators and after
> commas, also makes the code much easier to read.
>
> From now on, if you post a chunk of nearly illegible code like what
> you posted upthread, with no indentation and virtually no whitespace,
> I will ask you to format it properly before I'll even consider helping
> you fix any other problems.
OK
Bill


|