I was just testing the CLI for my application, and I noticed that fgets isn't waiting for a response all the time. It's a good bit more complex than this, but here's a patchwork example:
Code:
void start(struct outline_interface *this){
unsigned short length = 31;
char *command = (char *)NULL, *arguments = (char *)NULL;
char *space;
unsigned short valid;
while(1){
printf("Enter a command. > ")
fgets(command, (int)length, stdin);
/* [putting everything after the first space out of 'command' and into 'arguments'] */
if(strcmp("make", command) == 0){
char response[4];
printf("No outline with this name is currently in memory; do you want to load it? (yes, no)");
fgets(response, 4, stdin);
if(strcmp(response, "yes") == 0)
this->load(this, arguments); /* performs no user I/O */
printf("These messages may be avoided by using the otherwise identical \"load\" command to create/load outlines.");
}
/* [checking for exit conditions] */
}
}
When I run it, I reply to two prompts and then one "skips," taking an empty string as input:
Code:
Enter a command. > make Test
No outline with this name is currently in memory; do you want to load it? (no, yes) > yes
These messages may be avoided by using the otherwise identical "load" command to create/load outlines.
[formatted user input]
Enter a command. > Invalid input. Type "help" for a list of accepted commands.
Enter a command. >
What could cause that? Do I need to system("pause")?
Thanks!