I have a program that accepts input from the command line. While all of the available commands are one string, several of the commands require a secondary string to further define the action.
e.g. “end” is one command, and “add foo” is a second.
My code handles the 2 string inputs fine, but when I try to access a single string command (such as “end”) the program waits for more input instead of acting immediately.
Is there some way I can get the program to read in exactly one line (which may have up to two strings) rather than the way it is now?
Here’s how it’s currently implemented:
while(1)
{
scanf("%s%s", commandString,floorPath);
if(!strcmp(commandString,"end") return;
//I've got several of these as an "if / else", but there's no
//need to reprint them here.
}
Read the first string alone, and depending on the input decide if there is a need to read another string or not.