Thread: Command Interface : Black Box testing

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    7

    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?

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    int main(command)
    Main does not take 'command' as a parameter. Use:
    Code:
    int main( void )
    
    or
    
    int main( int argc, char *argv[] )
    Because really, what the hell is 'command' as far as your compiler is concerned? That's exactly what it's wondering.
    Code:
    getCommand();
    You are doing nothing with the return value. Why?
    Code:
    switch( getCommand( ) )
    That would be much better.

    Additionally, why do your functions return values if you never use them? Make main return 0 when it is done, and make your other function return the value the user enters.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 02-13-2008, 02:59 PM
  2. How to program a "back" button with MFC
    By 99atlantic in forum Windows Programming
    Replies: 3
    Last Post: 04-26-2005, 08:34 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 08:00 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM