Thread View: net.unix
6 messages
6 total messages
Started by Robert L Krawitz
Sat, 01 Nov 1986 17:43
strtol()
Author: Robert L Krawitz
Date: Sat, 01 Nov 1986 17:43
Date: Sat, 01 Nov 1986 17:43
15 lines
841 bytes
841 bytes
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. (The reason I'm cross-posting it to net.bicycle is that
that's where the particlar program came from.)
Example:
long strtol();
getnum()
{
return (int)strtol(lineptr, &lineptr, 10);
}
--
Robert^Z
Re: strtol()
Author: David Langdon
Date: Mon, 03 Nov 1986 16:54
Date: Mon, 03 Nov 1986 16:54
27 lines
1322 bytes
1322 bytes
> Xref: rabbit1 net.unix:1814 net.bicycle:619
> rlk@mit-trillian.MIT.EDU (Robert L Krawitz): writes
>
> 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. (The reason I'm cross-posting it to net.bicycle is that
> that's where the particlar program came from.)
>
> Example:
>
> long strtol();
>
> getnum()
> {
> return (int)strtol(lineptr, &lineptr, 10);
> }
> --
> Robert^Z
If I'm not mistaken, strtol() is "string-to-long" conversion routine. It
takes an ASCII string and converts it to a long value type
--
David Langdon Rabbit Software Corp.
(215) 647-0440 7 Great Valley Parkway East Malvern PA 19355
...!ihnp4!{cbmvax,cuuxb}!hutch!dml ...!psuvax1!burdvax!hutch!dml
Re: strtol()
Author: Guy Harris
Date: Mon, 03 Nov 1986 19:18
Date: Mon, 03 Nov 1986 19:18
23 lines
1393 bytes
1393 bytes
> 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@sun.com (or guy@sun.arpa)
Re: strtol()
Author: carroll
Date: Mon, 03 Nov 1986 21:32
Date: Mon, 03 Nov 1986 21:32
19 lines
1262 bytes
1262 bytes
From the SysV "Programmers Reference Manual" : long strtol(str,ptr,base) char *str,**ptr; int base; Strtol returns as a long integer the value represented by the character string pointed to by str. The string is scanned up to the first character inconsistent with the base. Leading whitespace is ignored. If ptr is not NULL, a pointer to the character terminating the scan is returned. If base is positive (and <= 36), it is used as the base for conversion. After an optional leading minus sign, leading zero's are ignored, and a leading 0X or 0x is ignored if base == 16. If base is zero, then a leading zero indicates base 8, leading 0x or 0X indicates base 16, otherwise it is base 10.
Re: strtol()
Author: Robert N. Berlinger
Date: Wed, 05 Nov 1986 00:53
Date: Wed, 05 Nov 1986 00:53
45 lines
2215 bytes
2215 bytes
> What does strtol() do?
This is from the AT&T manual.
SYNOPSIS
long strtol (str, ptr, base)
char *str, **ptr;
int base;
DESCRIPTION
Strtol returns as a long integer the value represented by
the character string pointed to by str. The string is
scanned up to the first character inconsistent with the
base. Leading ``white-space'' characters (as defined by
isspace in ctype(3C)) are ignored.
If the value of ptr is not (char **)NULL, a pointer to the
character terminating the scan is returned in the location
pointed to by ptr. If no integer can be formed, that
location is set to str, and zero is returned.
If base is positive (and not greater than 36), it is used as
the base for conversion. After an optional leading sign,
leading zeros are ignored, and ``0x'' or ``0X'' is ignored
if base is 16.
If base is zero, the string itself determines the base
thusly: After an optional leading sign a leading zero
indicates octal conversion, and a leading ``0x'' or ``0X''
hexadecimal conversion. Otherwise, decimal conversion is
used.
Truncation from long to int can, of course, take place upon
assignment or by an explicit cast.
Hope that helps.
--
Robert N. Berlinger
Systems Analyst
Scientific Computing Center
Albert Einstein College of Medicine
UUCP: ...{philabs,cucard,pegasus,ima,rocky2}!aecom!naftoli
Compuserve: 73047,741
Easylink: 62956067
GEnie: R.Berlinger
Re: strtol()
Author: Greg Franks
Date: Thu, 06 Nov 1986 19:34
Date: Thu, 06 Nov 1986 19:34
34 lines
1541 bytes
1541 bytes
In article <1366@mit-trillian.MIT.EDU> rlk@athena.MIT.EDU writes:
>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. (The reason I'm cross-posting it to net.bicycle is that
>that's where the particlar program came from.)
Our XENIX systems lack strtol too. My solution:
getnum()
{
#ifdef V7
int i;
if ( sscanf( lineptr, "%d", &i ) > 0 ) {
while( isspace( *lineptr ) )
lineptr++;
while( isdigit( *lineptr ) )
lineptr++;
} else
i = 0;
return( i );
#else
return (int)strtol(lineptr, &lineptr, 10);
#endif
}
Strtol(3) adjusts lineptr by the number of characters eaten. So, after
successfully grabbing the number using sscanf (which skips white space)
adjust the pointer the hard way.
There are public domain versions of strtok. Henry Spencer (utzoo)
wrote one - I used his...
Good luck!
..greg
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads