strtol()

Greg Franks greg at xios.UUCP
Fri Nov 7 05:34:06 AEST 1986


In article <1366 at mit-trillian.MIT.EDU> rlk at 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



More information about the Comp.unix mailing list