I'm not sure what you are actually asking: I presume that what you are really looking for is either:
1. A way to read an integer, checking each character to see if the character is valid.
2. Check if what you read (using integer format to scanf()) was accepted by scanf().
The second option is the easier one:
The function scanf() will return "the number of correctly entered fields", so if you do
Code:
int n;
int r;
r = scanf("%d", &n);
if (r == 1) {
// Something got accepted as a number.
} else {
// Error, nothing accepted.
}
The above code will not accept "abc", but WILL accept "1234abc" as 1234, leaving "abc" in the input buffer. Another scanf() trying to read an integer from the input buffer of "abc" will not accept the further input of "abc".
Alternatively, you use getchar() to read each character, and you "build" the number up yourself. This is possibly what you are supposed to do.
Code:
int c;
int n;
do {
c = getchar();
if (isdigit(c)) {
// form a number
} else if (c == '\n') {
// done - but may be "empty" number.
} else {
// Error - something that wasn't a digit entered.
}
} while (moretodo);
This will ensure that ALL the input was accepted, and that there was no input beyond the "number".
Note that BOTH will require you to also remove any "garbage" from the input buffer if the input isn't accepted.
--
Mats