Standard C Functions


strtol


Syntax

#include <stdlib.h>
long strtol(const char *string, char **endptr, int base)

Arguments

string      character string to be converted
endptr      pointer to a pointer to an unrecognizable character string
base        the radix (for bases from 2 to 36); if 0 is specified as the radix, the actual 
            radix is obtained by using the first one or two characters of the string 

Return Value

The converted numeric unsigned long value of the character string

Description

It converts a specified character string to a numeric value with an unsigned long type by parsing the string using this format:

[whitespace][{sign}][{0}][{x | X}][digits]
<whitespace>
spaces, NULL characters, or tab characters

<sign>
+ or -

<digits>
a string of more than one numeric characters

If 0 is specified as the radix base, the radix is interpreted as follows:

Conversion is terminated when an unrecognizable character appears as a part of the number.

If endptr is not NULL, it points to *endptr which points to the unrecognizable character that terminated the conversion.