Moving around in functions
I have this simple situation where I call a void function within another function:
Code:
void prompt() {
char command = '\0';
int numScanned = 0;
printf("? ");
numScanned = scanf("%c", &command);
while (numScanned == 1) {
if (command == 'h') {
helpCommand();
}
printf("? ");
numScanned = scanf("%c", &command);
}
}
Basically the program will query the user with
?
and then it will expect a character to be entered. If the character is equivalent to h then it will call a void function called helpCommand which is just a function that prints stuff. The problem however is that when I run the program I'm getting the results
? h
<helpCommand output>
? ?
notice the double question marks, or even if I input something other than h I get
? a
? ?
which is clearly happening because it's printing the second question mark within the while loop and then somehow it's going back to the beginning of the prompt function and printing the first question mark? I'm really confused about this, and I've also checked to see what is in the character variable command after the scanf in the while loop and it doesn't print out anything (or it's possibly a space, blank, etc.).
Can anyone please explain what is happening here?