rlk@mit-trillian.MIT.EDU (Robert L Krawitz) (11/01/86)
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
dml@rabbit1.UUCP (David Langdon) (11/03/86)
> 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
naftoli@aecom.UUCP (Robert N. Berlinger) (11/05/86)
> 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
greg@xios.UUCP (Greg Franks) (11/06/86)
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