Sujet : The difference between strtol() and strtoul() ?
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : comp.lang.cDate : 20. Jun 2024, 15:06:45
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <v51d1l$2fklr$1@news.xmission.com>
User-Agent : trn 4.0-test77 (Sep 1, 2010)
Interestingly, I note that strtoul() accepts strings that begin with a sign
(+ or -). This is odd, since you'd (*) think that a sign (particularly, a
minus) would be a syntax error in parsing for an unsigned value.
Further, although the (Linux) man page is more than a bit murky on the
subject, it seems that the result of parsing, say, "-1", with strtoul() is
the largest unsigned value (usually, 2**N-1 or a lot of F's (in hex)).
Whereas, I would expect it to be 1 (i.e., just take the absolute value).
Comments? I find this all very counterintuitive.
(*) Or should I say, "one would" ?
P.S. Why isn't there a strtoi() or strtou() ? I know, of course, that
there is atoi(), but that doesn't have the error checking capability that
the strto* functions have.
-- If you think you have any objections to anything I've said above, pleasenavigate to this URL: http://www.xmission.com/~gazelle/TruthThis should clear up any misconceptions you may have.