Using the "%n"
records where the scan is in the buffer.
We can use it to determine what stopped the scan.
int n;
int res = sscanf(string, "%"SCNu32 " %n", &temp, &n);
if (0 != errno || 1 != res || string[n] != '\0')
return HEX_ECONVERSION;
Appending " %n"
says to ignore following white-space, then note the buffer position. If there is not additional junk like ".5"
, the string[n]
will point to the null terminator.
Be sure to test n
after insuring temp
was set. This was done above with 1 != res
.
"%n"
does not affect the value returned by sscanf()
.