Strtol and strtoul...
Chris Torek
chris at mimsy.umd.edu
Sat Dec 16 10:44:52 AEST 1989
In article <3233 at com50.C2S.MN.ORG> markc at com2serv.c2s.mn.org
(Mark H. Colburn) writes:
> unsigned long foo;
> char *ptr;
>
> foo = strtoul("-12345", &ptr, 0);
>... where would ptr point to? The call should return ULONG_MAX with errno
>set to ERANGE, but does *ptr = '-' or '\0' (end of string) or is it
>indeterminate? It looks as if it should point to '\0', but...
It should return (unsigned long)-12345, which is typically either
53191 or 4294954951, and leave *ptr=='\0'. For
foo = strtoul("340282366920938463463374607431768211456", &ptr, 0);
which *is* too big (unless you have 128 bit `long's), it should
return ULONG_MAX, errno==ERANGE, and *ptr=='\0'.
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at cs.umd.edu Path: uunet!mimsy!chris
More information about the Comp.lang.c
mailing list