This program is suposed to verify that the user input a integer. Give back an error if the datatype is incorect or if the input is empty. But only one time. I want to transform this program to keep asking the user until the answer is good.Here its a "single-use" programs , but i want it to do it with a while but its infinite.
#include <stdio.h>
int main()
{
int num;
char term;
if(scanf("%d%c", &num, &term) != 2 || term != '\n')
{
printf("failure\n");
}
else
{
printf("valid integer followed by enter key\n");
}
return 0;
}
scanf()to work correctly. If there are 3 iterations thenscanf()will work when they are all input on the same line. So really, the next character test should be for whitespace using!isspace(term).while/do whileand pass your condition to it then loop will continue till user enter the proper(As per requirement) input