3 ms·
strto*() is the wrong API to use if you care about errors. char* forty_two = 42; int i; if (sscanf (forty_two, "%d", &i) != 1) { /* error */ } S
by PaulDavisThe1st 5y ago
strto*() is the wrong API to use if you care about errors.
char* forty_two = 42;
int i;
if (sscanf (forty_two, "%d", &i) != 1) {
/* error */
}
Sometimes, there's more than one way to skin a cat, and one of them is more suited to the task at hand.
- JulianMorrison 5y agoNow what happens if you pass it a string without a null byte terminator?
- PaulDavisThe1st 5y agoI made no claim that using sscanf instead of strto* fixes all the issues with C string represenation.