*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->IRIX man pages -> strtol (3c)              
Title
Content
Arch
Section
 

Contents


strtol(3C)							    strtol(3C)


NAME    [Toc]    [Back]

     strtol, strtoul, atol, atoi, strtoll, strtoull, atoll - convert string to
     integer

SYNOPSIS    [Toc]    [Back]

     #include <stdlib.h>

     long strtol (const	char *str, char	**ptr, int base);

     unsigned long strtoul (const char *str, char **ptr, int base);

     long long strtoll (const char *str, char **ptr, int base);

     unsigned long long	strtoull (const	char *str, char	**ptr, int base);

     int atoi (const char *str);

     long atol (const char *str);

     long long atoll (const char *str);

DESCRIPTION    [Toc]    [Back]

     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	between	2 and 36, inclusive, 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 as follows:	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.

     If	the value represented by str would cause overflow, LONG_MAX or
     LONG_MIN is returned (according to	the sign of the	value),	and errno is
     set to the	value, ERANGE.

     strtoul is	similar	to strtol except that strtoul returns as an unsigned
     long integer the value represented	by str.	 If the	value represented by
     str would cause overflow, ULONG_MAX is returned, and errno	is set to the
     value, ERANGE.



									Page 1






strtol(3C)							    strtol(3C)



     strtoll is	similar	to strtol except that strtoll returns as a long	long
     integer the value represented by str.  If the value represented by	str
     would cause overflow, LONGLONG_MAX	or LONGLONG_MIN	is returned (according
     to	the sign of the	value),	and errno is set to the	value, ERANGE.

     strtoull is similar to strtoll except that	strtoull returns as an
     unsigned long long	integer	the value represented by str.  If the value
     represented by str	would cause overflow, ULONGLONG_MAX is returned, and
     errno is set to the value,	ERANGE.

     Except for	behavior on error, atol(str) is	equivalent to:
	  strtol(str, (char **)NULL, 10)

     Except for	behavior on error, atoi(str) is	equivalent to:
	  (int)	strtol(str, (char **)NULL, 10)

     Except for	behavior on error, atoll(str) is equivalent to:
	  strtoll(str, (char **)NULL, 10)

DIAGNOSTICS    [Toc]    [Back]

     If	strtol is given	a base greater than 36 or less than 2, it returns 0
     and sets errno to EINVAL.

SEE ALSO    [Toc]    [Back]

      
      
     ctype(3C),	strtod(3C), scanf(3S).

NOTES    [Toc]    [Back]

     strtol no longer accepts values greater than LONG_MAX as valid input.
     Use strtoul instead.


									PPPPaaaaggggeeee 2222
[ Back ]
 Similar pages
Name OS Title
atoi Linux convert a string to an integer.
atoi FreeBSD convert ASCII string to integer
atoi OpenBSD convert ASCII string to integer
strtol Linux convert a string to a long integer.
atoi NetBSD convert ASCII string to integer
strtonum OpenBSD reliably convert string value to an integer
getint IRIX convert from string to integer, double, or boolean
atol NetBSD convert ASCII string to long integer
a64l OpenBSD convert between 32-bit integer and radix-64 ASCII string
strtoul Linux convert a string to an unsigned long integer.
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service