3 ms·
From the article: char *forty_two_bee = "42b"; char *end; errno = 0; // remember errno? long i = strtol(forty_two_bee, &end, 10); > This will return
by stncls 5y ago
From the article:
char *forty_two_bee = "42b";
char *end;
errno = 0; // remember errno?
long i = strtol(forty_two_bee, &end, 10);
> This will return 0
No, this will return 42. strtol() parses greedily until a character cannot be parsed, but then it returns the conversion of what it did parse.
I guess the fact the author got this wrong... kind of proves their point that strtol()'s API is not great?
On the other hand, while the article purports to criticize a language, it then proceeds to only cover its standard library. Sure, C's stdlib is old-fashioned, but there are many things in C that are much worse than its standard library! (And I say that as someone who still likes the language.)