Can somebody please explain why I'm getting a double print out of the actions inside the loop (a simple printf() message) every time I enter a character?
Code:
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
main() {
// Only pressing a numerical key will make a system call to clear the screen
char x;
do {
printf("\nPress any numerical digit to clear the screen:");
scanf("%c", &x);
} while ( isdigit(x) == 0 );
system("clear");
} // end of main()
The isdigit() validation seems to be working. What I'm not understanding is why the printf() message appears twice if I enter a character.
Thanks.