Command Interface : Black Box testing
Code:
#include <stdio.h>
#include <stdlib.h>
typedef enum boolean {FALSE, TRUE}Boolean;
char getCommand(command);
int main(command)
{
getCommand();
switch(command)
{
case 'F':
printf("Flagged Current Mine");
break;
case 'U':
printf("Uncovered Cell");
break;
case 'R':
printf("Removed a flag");
break;
case 'Q':
printf("Quit Game");
break;
case 'N':
printf("New Game");
break;
default: printf("The value you entered is not valid");
break;
}
}
char getCommand(void)
{
char command;
printf("Please Enter A Minesweeper Command\n"
"[F]lag a Cell\n"
"[U]ncover a cell\n"
"[R]emove a flag\n"
"[Q]uit game\n"
"[N]ew game\n\n");
while(TRUE){
while((command = getchar()) == '\n');
command = toupper(command);
if ( command == 'F' || command == 'U' ||
command == 'R' || command == 'Q' ||
command == 'N'){
while (getchar() !='\n');
return command;
}
}
}
This is my code, the object is to just have a small main program to test the choices for validity, but when I type in any invalid selection it just skips a line, and when I type in a valid selection, it comes up with the default switch value, any clue why?