strtol()
Guy Harris
guy at sun.uucp
Tue Nov 4 05:18:02 AEST 1986
> What does this do? It doesn't seem to exist on my 4.3 system. I
> suspect it's a SysV library fn, so it seems like I'll have to write it
> myself.
Yes, it's a generalization of "atol"; it first appeared in System V. It is
passed a pointer to a "char *"; if this pointer is non-null, it will return
a pointer to the first character after the value it converted. It is also
passed a radix, so it can convert hex or octal numbers; if the radix is 0,
it converts the number as if it were a C constant (if it begins with "0x",
it's hex; otherwise, if it begins with "0", it's octal; otherwise, it's
decimal).
> getnum()
> {
> return (int)strtol(lineptr, &lineptr, 10);
> }
As you can probably infer, the "pointer to pointer" is the second argument
and the radix is the third argument.
--
Guy Harris
{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
guy at sun.com (or guy at sun.arpa)
More information about the Comp.unix
mailing list