I need to check if a C string is a valid integer.
I tried both
int num=atoi(str);
and
int res=sscanf(str, "%d", &num);
But sending the string "8 -9 10" in both of the lines returned simply 8, without indicating the invalidity of this string.
Can anyone suggest an alternative?
Have a look at strtol(), it can tell you about invalid parts of the string by pointer return.
And beware of enthusiastic example code.. see the man page for comprehensive error-handling.