You can try reading the next character and analyzing it. Something along the lines of
int n;
char c;
for (int i = 0;
(n = scanf("%d%c", &val, &c)) == 1 || (n == 2 && isspace(c));
i++)
...
// Include into the test whatever characters you see as acceptable after a number
or, in an attempt to create something "fancier"
for (int i = 0;
scanf("%d%1[^ \n\t]", &val, (char[2]) { 0 }) == 1;
i++)
...
// Include into the `[^...]` set whatever characters you see as acceptable after a number
But in general you will probably run into limitations of scanf
rather quickly. It is a better idea to read your input as a string and parse/analyze it afterwards.