In my programm I want to give as input a number from 0 to 100 and I need to deal with the situation in which a bad user of the program might give character(s) as input (while they shouldn't!).
I've done this:
Code:
int num;
printf("Give number of names:\n");
int flag=scanf("%d",&num);
while(flag!=1 || num<0 || num>100)
{
printf("Give number of names:\n");
flag=scanf("%d",&num);
}
When I run this piece of ..... code and give characters for input, I get some great output:
Give number of names:
Give number of names:
Give number of names:
Give number of names:
....and keeps going forever....
Anyone could share some ideas?