There is a similar question here(on which this question is based)
Check if input is integer type in C and related answer https://stackoverflow.com/a/4072483/3395716
The difference is that in that answer only one integer is checked, but I want to check multiple numbers and then quit.
I modified the program like this,
//variable declaration
flag=0;
if(scanf("%d%c", &A, &term) != 2 || term != '\n')
{
flag=1;
}
if(scanf("%d%c",&B, &term) != 2 || term != '\n')
{
flag=1;
}
if(scanf("%d%c",&C,&term) != 2 || term != '\n')
{
flag=1;
}
if(flag==1)
{
printf("failure\n");
return 0;
}
The problem is, the program doesn't wait for all numbers to be inputed, rather if, say first input is invalid, it will just print failure
.
What should I do?
EDIT: example input and output
5
6
7
output:nothing
expected
input:
5
f
7
output:failure
what happens
5
f
output:failure