Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > S

strtol(3C)

HP-UX 11i Version 3: February 2007
» 

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index

NAME

strtol(), atol(), atoll(), atoi(), strtoul(), strtoll(), strtoull() — convert string to integer

SYNOPSIS

#include <stdlib.h>

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

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

long atol(const char *str);

long long atoll(const char *str);

int atoi(const char *str);

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

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

DESCRIPTION

strtol() or strtoul() converts the character string pointed to by str to long int or unsigned long int representation, respectively. strtoll() or strtoull() converts the character string pointed to by str to long long or unsigned long long representation, respectively. 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 no conversion can take place, zero is returned.

If base is greater than or equal to 2 and less than or equal to 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 as follows: after an optional leading sign, a leading zero indicates octal conversion; a leading 0x or 0X indicates hexadecimal conversion. Otherwise, decimal conversion is used.

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, the location pointed to by ptr is set to str, and zero is returned.

atol(str) is equivalent to strtol(str, (char **)NULL, 10).

atoll(str) is equivalent to strtoll(str, (char **)NULL, 10).

atoi(str) is equivalent to int strtol(str, (char **)NULL, 10).

RETURN VALUE

Upon successful completion, all functions return the converted value, if any.

If the correct value would cause overflow:

strtol()

returns LONG_MAX or LONG_MIN (according to the sign of the value), and sets errno to ERANGE.

strtoul()

returns ULONG_MAX and sets errno to ERANGE.

strtoll()

returns LLONG_MAX or LLONG_MIN (according to the sign of the value), and sets errno to ERANGE.

strtoull()

returns ULLONG_MAX and sets errno to ERANGE.

atoll()

returns LLONG_MAX or LLONG_MIN (according to the sign of the value), and sets errno to ERANGE.

For all other errors, zero is returned and errno is set to indicate the error.

ERRORS

strtol(), strtoul(), strtoll() and strtoull() fail and errno is set, if any of the following conditions are encountered:

EINVAL

The value of base is not supported.

ERANGE

The value to be returned would have caused overflow.

AUTHOR

These interfaces were developed by OSF and HP.

STANDARDS CONFORMANCE

strtol(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, ANSI C

atoi(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C

atol(): AES, SVID2, SVID3, XPG2, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C

atoll(): C99

strtoul(): AES, SVID3, XPG4, ANSI C

strtoll(): C99

strtoull(): C99

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.