-
breaking out of program
In regards to the default case, i need the prog to only end if there is no input. If i put return 0; the prog ends only after one loop, and if i put break; the prog never ends.
Can anyone tell me how i fix this?
Code:
int main(){
while ( fgets( buff, BUFSIZ, stdin ) != NULL ) {
switch ( buff[0] ) {
case '0':
one (buff);
break;
case '1':
one (buff);
break;
case '2':
one (buff);
break;
case '3':
one (buff);
break;
case '4':
one (buff);
break;
case '5':
one (buff);
break;
case '6':
one (buff);
break;
case '7':
one (buff);
break;
case '8':
one (buff);
break;
case '9':
one (buff);
break;
default:
two(buff);
return 0;
}
}
}
-
Code:
int main(){
int quit = 0;
while ( !quit && fgets( buff, BUFSIZ, stdin ) != NULL ) {
switch ( buff[0] ) {
case '0':
one (buff);
break;
default:
two(buff);
quit = 1;
}
}
}
-
I'm still relatively new to C programming, although I completed a university course in programming with C. ^^; Haven't had much practice since then. :p
Anyway, my question is, is it unprofessional to use a Go to statement in a case like this?
-
>is it unprofessional to use a Go to statement in a case like this?
Not as long as you can defend your choice of using goto to every yahoo who reads your code. :rolleyes:
-