Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Re: program bug
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 11 of 36 Topic 26044 of 26959
Post > Topic >>

Re: program bug

by "Bill Cunningham" <nospam@[EMAIL PROTECTED] > May 3, 2008 at 10:58 PM

"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
 




 36 Posts in Topic:
program bug
"Bill Cunningham&quo  2008-05-02 21:40:19 
Re: program bug
"Bill Cunningham&quo  2008-05-02 21:53:34 
Re: program bug
Robert Gamble <rgamble  2008-05-02 15:08:03 
Re: program bug
Robert Gamble <rgamble  2008-05-02 15:05:58 
Re: program bug
"Bill Cunningham&quo  2008-05-02 22:16:27 
Re: program bug
CBFalconer <cbfalconer  2008-05-02 18:47:28 
Re: program bug
"Bill Cunningham&quo  2008-05-02 22:21:04 
Re: program bug
Robert Gamble <rgamble  2008-05-02 15:28:04 
Re: program bug
"Bill Cunningham&quo  2008-05-03 20:42:30 
Re: program bug
Keith Thompson <kst-u@  2008-05-03 14:48:48 
Re: program bug
"Bill Cunningham&quo  2008-05-03 22:58:24 
Re: program bug
Keith Thompson <kst-u@  2008-05-03 18:08:44 
Re: program bug
"Default User"   2008-05-04 03:20:33 
Re: program bug
Keith Thompson <kst-u@  2008-05-03 21:17:13 
Re: program bug
"Default User"   2008-05-04 19:03:07 
Re: program bug
vippstar@[EMAIL PROTECTED  2008-05-03 16:21:48 
Re: program bug
CBFalconer <cbfalconer  2008-05-03 20:29:01 
Re: program bug
Joe Wright <joewwright  2008-05-02 18:25:33 
Re: program bug
Ian Collins <ian-news@  2008-05-03 10:28:17 
Re: program bug
"Bill Cunningham&quo  2008-05-02 22:36:04 
Re: program bug
Robert Gamble <rgamble  2008-05-02 15:36:31 
Re: program bug
Ian Collins <ian-news@  2008-05-03 11:31:53 
Re: program bug
Joe Wright <joewwright  2008-05-02 20:18:17 
Re: program bug
Ian Collins <ian-news@  2008-05-03 12:31:09 
Re: program bug
"Bill Cunningham&quo  2008-05-02 23:15:17 
Re: program bug
Keith Thompson <kst-u@  2008-05-02 23:56:46 
Re: program bug
Richard Heathfield <rj  2008-05-03 07:04:24 
Re: program bug
CBFalconer <cbfalconer  2008-05-02 18:50:15 
Re: program bug
user923005 <dcorbit@[E  2008-05-02 21:25:53 
Re: program bug
"Bill Cunningham&quo  2008-05-03 15:52:27 
Re: program bug
vippstar@[EMAIL PROTECTED  2008-05-03 09:01:52 
Re: program bug
Eligiusz Narutowicz<el  2008-05-04 08:41:56 
Re: program bug
"Bill Cunningham&quo  2008-05-04 21:25:27 
Re: program bug
Barry Schwarz <schwarz  2008-05-04 15:20:34 
Re: program bug
"Bill Cunningham&quo  2008-05-06 02:30:36 
Re: program bug
Nick Keighley <nick_ke  2008-05-06 02:28:14 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 16:10:16 CDT 2008.