In <vzSdp.4941$%> "Alexo" <> writes:
> do{
> printf("\ninsert an integer number ");
> b = scanf("%d", &a);
> }while( b != 1 );
> try to execute it inputing a character instead of an integer number. The
> loop never ends.
> I would like that the loop be executed only once when the scanf fails.
> Thank you in advance
If you want the input prompt to appear only once, then why did you put
it inside a loop?
Perhaps you want something more like this:
char input_buffer[99];
printf("\ninsert an integer number ");
fflush(stdout);
fgets(input_buffer, sizeof(input_buffer), stdin);
b = sscanf(input_buffer, "%d", &a);
if (b == 1)
printf("\nThe number inserted is %d\n", a);
else
printf("You did not enter a number. Shame on you!\n");
--
John Gordon A is for Amy, who fell down the stairs
B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"