show the menu only once each time..
when i input a number which is out of range it prints the menu again so in a single letter case.
but when i input "abc" it prints the menu 3 times in fact the number of menu print
depends on the number of chars in the strings.
how to do tat no matter what wrong input i will give it,it will print the menu again only once??
Code:
#include <stdio.h>
#define N 9
void mainMenu();
int main()
{
char input[40];
char input2[40];
char board[N][N];
mainPlayGame(board);
printf("bye, please press enter to exit!\n");
getchar();
return 0;
}
void mainPlayGame(board){
int opt,leng,size=-1;
int index,kndex;
char input[40];
char ch_cords[40];
char input2[40];
int tr;
int cords[8][2];
int tndex;
int i,k,j,ch,l;
int leng2;
do
{
mainMenu();
scanf("%d",&opt);
l=getchar();
if (opt==1)
{
printf("1");
}
if (opt==2)
{
printf("2");
}
if (opt==3)
{
printf("3");
}
if (opt==4)
{
printf("4");
}
if (opt==5)
{
printf("5");
}
if (opt==0){
}
}while(opt!=0);
}
int playGame(char board[N][N],int size){
}
void mainMenu() {
printf("--------------------------\n");
printf("welcome to the game\n");
printf("1. choose board size\n");
printf("2. place mines\n");
printf("3. remove mines\n");
printf("4. show mines\n");
printf("5. start the game\n");
printf("0. exit\n");
printf("please enter your choice (input control is needed): \n");
}