[Courses] [C] lesson8 questions & answers

Morgon Kanter admin at surgo.net
Sun Nov 10 16:35:48 EST 2002


First, my question:
Hey, why do we keep doing
#include <stdio.h>
at the beginning of programs? printf doesn't even seem 
to be a part of that, as this change of one of your examples 
compiles and works just fine:

/* extra lines taken out for compactness in email */
main() {
 int i;
 for(i=0;i<3;i++) {
  int temporary = 1;
  static int permanent = 1;
  printf("Temporary is %d, permanent is %d\n", temporary, permanent);
  temporary++;
  permanent++;
 }
}

debugging answer: 
for(i=0;string[i] !='\0' ;i++) return i; /* will return i=0, then not go
				  again because already 
				  returned */
/* instead, do */
for(i=0;string[i] != '\0';i++);
return i;




More information about the Courses mailing list