I need a help with the following function, it's expecting an integer input; and when I insert something like "F" (non-numerical characters ), the program gets stuck, it doesn't show any output or let me insert more inputs. how can this be fixed?
int input_legality(int game_board[FIELD_ROWS][FIELD_COLS])
{
int input=0;
while(1)
{
if(scanf("%d", &input)==1)
{
if(input==DOWN || input==LEFT || input==RIGHT || input==UP)
{
return input;
}
else
if(input==EXIT)
{
printf("\n program exited by user \n");
return 1;
}
else
if(input==PRINT)
{
printField(game_board);
continue;
}
else
{
fprintf(stderr,"your step is undefined, please try another one\n");
continue;
}
}
}
return 0;
}