I started to use the sscanf function to parse commands from serial port and found out that it does not work as it must do. Example:
int i, j = 0x1234; char c = '\0'; i = sscanf("anything", "%d%c", &j, &c);
Since sscanf() does not appear to be returning after the first conversion (matching) failure, you might want to consider using the strtol() or strtoul() functions to convert the integer portions of the strings. These functions provide extra "feedback" about the progress of their conversions.
As soon as I read my own question the answer came to me :-) I can detect errors in the input by checking if the c field has been modified by sscanf (since I cannot rely on the return value). It will do as a workaround. Clearly there is an error in the implementation of a library function. Hopefully, Keil Software will fix that soon.
Just a comment, scanf() is a notoriously dangerous function, even for experts. Best to fgets() the line and parse it out safely in memory. - Mark
What version of C51 are you using? Jon
It's C166, latest version.