Share this page

# strtol

String Manipulation Functions

Converts a string to a long integer using a given radix.

    long strtol( const char *string, char **endptr, int radix );

string | String representing an integer number. The number is considered until a non-numeric character is found . Use the following format: [whitespaces][+|-][0|0x][nnnnn] (where whitespaces are tab or space character and nnnnn is a sequence of valid numbers following the specified radix)
endptr | An address of a pointer.
radix | Numeral radix in which the number to be interpreted. Must be 0 or be between 2 and 36. If it is 0 the radix of the string is determined by the initial characters of the string: 0x for hex, 0 for octal, and 1-9 for decimal.

strtol scans the initial portion of the string only, by stopping at the first non-numerical character. Any preceding white spaces are stripped. endptr points to the character that stopped the scan.

## Return Values

The converted long int value from the input string. If conversion would cause overflow the result is LONG_MAX or LONG_MIN. If an error occurs or no conversion can be made, returns 0.

## Example

The following example converts the first number it reads in string, str, to a long integer. It reads the rest of the string into end_string.

        #include <string.h>
        long l;
        char * end_string, * str = "-569357608END HERE";
        l = strtol(str, &end_string, 10);
        lr_output_message ("long=%ld followed by %s", l, end_string);

    Example: Output:
    Action.c(11): long=-569357608 followed by END HERE

Tips to improve your search results... VuGen Function Reference Version 26.1 Function Reference 26.1 All View Local Help Center View Online Help Center Version: