On Fri, 16 Oct 1998, James [on his mailserver] wrote:
> why doesn't this work:
> 
> {
>       int c;
> 
>       for (c=0; c==9; c++)
>               /* something */
> }
> 
> i tried it once and it didn't work as expected (i can't remember what
> happened, it either looped for ever, or just skipped it).

i think it's 

  for((initialze vars); (while statement here TRUE); (modify vars)) 
  {
    /*something*/
  }

  in your case c==9 is initially false (you set c=0), so your for loop
will not execute and c will not be modified.


> 
> and, is this a Bad Thing...
> 
> {
>       for (int c=0; c<10; c++)
>               /* stuff */
> }
> 

this should work fine because c will not be incremented past 9


> And here's something that my C Programming tutor does:
> 
> main ()
> {
> /* whatever */
> exit (0);
> }
> 
> shouldn't it really be
> 
> int main ()
> {
> /* things */
> exit (0);
> 
> return (0);
> }
> 

any function (even main) which returns a value (!void) should have a
return statement i think, and might not need the exit statement unless you
are stopping the program abnormally.

> to conform to the ANSI C standard? doing gcc -Wall picks this up (type of
> main defaults to int) and i know this is just not done:
> 
> void main (void)
> {
> /* things */
> exit (0);
> }
> 
> :)
> 
> someone recommend a good C reference book (reference, not tutorial...)
> 
> 

Instant C++ was my favorite, but it falls along the definition of a
tutorial, although i used it for reference.  Text books are sometimes good
for reference since they don't walk you through things as much.  Try your
local university book store and see what the students are using. IMHO.

Best Regards,


Dan Jue
CMSC Stoodent
UMCP



Reply via email to