hey guys, im having a hard time making this switch function catch letters and return the error message.

int main()
{
    int choice;
    do
    {
         /* THE DISPLAY MENU*/
         printf("================================================\n\n");
         printf("Welcome to Walther's Tic Tac Toe Game.\n\n");
         printf("what would you like to do?\n\n");
         printf("1     Play Tic Tac Toe\n\n");
         printf("2     Quit\n\n");
         printf("Please make your selection now: ");
         scanf("%i", choice);
         printf("\n\n================================================\n");
         switch (choice)
              {
              case 1:
                   void ClearGameBoard(char board[]);
                   break;
              case 2:
                   
                   break;
              default:
                   printf("Your choice is invalid, please try again.\n");
                   break;                   
              }
    }while(choice != 2);    
    printf("Thank you for using James' converter. Bye!\n\n\n");
    system("PAUSE");
    return 0;
}

thanks as always ^.^

Recommended Answers

All 6 Replies

void ClearGameBoard(char board[]);

That's it a prototype of the function. Inside the switch, the call should be:

ClearGameBoard( board ); /* board is the name of any given string */

thanks ^.^ that woulda caught me up in the future. how can i create a net to catch a letter input and return the error message? what i have up there seems to be the simplest way, but it doesnt work >.< i get a infinite loop

thanks ^.^ that woulda caught me up in the future. how can i create a net to catch a letter input and return the error message? what i have up there seems to be the simplest way, but it doesnt work >.< i get a infinite loop

You have an amazing computer right there. Your program should crash.

scanf("%i", &choice); /* missing the & */

But forget all together scanf for picking characters. Too many problems with the extra left in the standard buffer stream.
Use fgets().

char choice[3];
do
{
	if ( fgets( choice, sizeof choice, stdin ) )
	{
		if ( choice[1] != '\n' )
		{
		 	while ( getchar() != '\n' );
		}
		switch (choice[0])
		{
			case '1':
				puts( "You chose 1" );
		   		break;
		  	case '2':
			   	break;
		  	default:
			   	printf("Your choice is invalid, please try again.\n");
                                break;                   
		}
	}
}while(choice[0] != '2');

Thanks Aia ^.^ the final touch of my tic tac toe is the very begining.

int main()
{
    int choice;
    do
    {
         /* THE DISPLAY MENU*/
         printf("================================================\n\n");
         printf("Welcome to Walther's Tic Tac Toe Game.\n\n");
         printf("what would you like to do?\n\n");
         printf("1     Play Tic Tac Toe\n\n");
         printf("2     Quit\n\n");
         printf("Please make your selection now: ");
         scanf("%i", choice);
         printf("\n\n================================================\n");
         switch (choice)
              {
              case 1:
                   void ClearGameBoard(char board[]);
                   break;
              case 2:
                   
                   break;
              default:
                   printf("Your choice is invalid, please try again.\n");
                   break;                   
              }
    }while(choice != 2);    
    printf("Thank you for using James' converter. Bye!\n\n\n");
    system("PAUSE");
    return 0;
}

sorry dude ddnt have the time

hey guys, im having a hard time making this switch function catch letters and return the error message.

int main()
{
    int choice;
    do
    {
         /* THE DISPLAY MENU*/
         printf("================================================\n\n");
         printf("Welcome to Walther's Tic Tac Toe Game.\n\n");
         printf("what would you like to do?\n\n");
         printf("1     Play Tic Tac Toe\n\n");
         printf("2     Quit\n\n");
         printf("Please make your selection now: ");
         scanf("%i", choice);
         printf("\n\n================================================\n");
         switch (choice)
              {
              case 1:
                   void ClearGameBoard(char board[]);
                   break;
              case 2:
                   
                   break;
              default:
                   printf("Your choice is invalid, please try again.\n");
                   break;                   
              }
    }while(choice != 2);    
    printf("Thank you for using James' converter. Bye!\n\n\n");
    system("PAUSE");
    return 0;
}

thanks as always ^.^

int main()
{
    int choice;
    do
    {
         /* THE DISPLAY MENU*/
         printf("================================================\n\n");
         printf("Welcome to Walther's Tic Tac Toe Game.\n\n");
         printf("what would you like to do?\n\n");
         printf("1     Play Tic Tac Toe\n\n");
         printf("2     Quit\n\n");
         printf("Please make your selection now: ");
         scanf("%i",&choice);
         printf("\n\n================================================\n");
         switch (choice)
              {
              case 1:
                   void ClearGameBoard(char board[]);
                   break;
              case 2:
                   
                   break;
              default:
                   printf("Your choice is invalid, please try again.\n");
                   break;                   
              }
    }while(choice != 2);    
    printf("Thank you for using James' converter. Bye!\n\n\n");
    system("PAUSE");
    return 0;
}

you have missed the ampersand in the scanf statement.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.