From Seo Wiki - Search Engine Optimization and Programming Languages

Jump to: navigation, search

The strtol (string to long integer) function in the C programming language is used to convert a string into an integer numerical representation:

long strtol(const char *restrict str, char **restrict end, int base)

The str argument points to a string, represented by an array of characters, containing the character representation of a signed integer value. The string must be null-terminated, as per normal C conventions. The base argument specifies the number base to use, from 2 to 36. Number bases greater than 10 use alphabetic characters ('A' up to 'Z') as digits. After the conversion, the value pointed to by end is set to point to the character following the last valid numeric character in the string and the converted integer value is returned. If the string does not contain a valid numerical sequence, zero (0) is returned and the global variable errno is set to EINVAL.

The strtoll variant of the function converts a string into a long long integer:

long long strtoll(const char *restrict str, char **restrict end, int base)

Similarly, the strtod function and its variants convert strings into floating-point values.

Standards conformance

The strtol function is part of the ISO standard C library (C89, 1989), and the strtoll function was added as part of the C99 library (1999). It was added to the standard C library as a more well-behaved replacement for the existing atoi function.


See also

Personal tools

Served in 0.053 secs.