I need my scanf to stop when it findes a spac/blank.
For exsample
If I type in “E E”, I only need 1 “E”, so it has to stop at space/blank.
char end[] = "E";
char end1[] = "End";
char info[] = "";
while(run) {
scanf("%s", &info);
...
else if(strcmp(info, end) == 0 || strcmp(info, end1) == 0) {
end_of_turn();
}
...
}
Now the problem here is that If I type in “E E”, it will run “end_of_turn” twice.
Does anyone know why it is so?
Edit:
Okay I can’t break the while loop, because that would stop the program.
use
breakto break out of thewhileloop? after callingend_of_turn()Or use a
gotostatement if you do not want to break out of the loop.You can also get all the characters from the input stream and then discard them using the code:
while(getchar() != '\n') ;