strtoul

Syntax

unsigned long strtoul(const char* nptr, char** endptr, int base)

Arguments

nptr
Pointer to the string containing the value to convert.
endptr
Optional storage space for output by this function.
base
The numerical base of the number, anything from 2 upto and including 36 or zero.

Return

The converted value from the string.

Description

This function will convert a string to an unsigned long value.
If the string would produce a negative value, it's result is negated so this function always returns the absolute value.
The string is expected to have optional leading white space followed by an optional plus (+) or minus (-) character and any number of digits.
If base is set to 16 (hexadecimal), the string may begin with an optional '0x' prefix.
If base is set to 0, the string will be parsed as having base 10 (decimal) unless it starts with '0x', in which case is is parsed as having base 16 (hexadecimal), or '0', in which case it is parsed as having base 8 (octal). This allows this function to parse C-style numbers.
If endptr is not NULL, a pointer to the next character after the parsed portion of the string is stored in the memory location reference by endptr.
If the resultant value would overflow the boundaries of the long datatype, the maximum possible value is returned. If an underflow would occur, zero will be returned. In both cases an errorcode will be set which can be queried.

Also see

strtod, strtol

Comments

Everyone can add his comments about his experiences with this function here. Tips for using it are welcome, too.