C Library Function - strtoul()
Description
C Library Function **unsigned long int strtoul(const char *str, char endptr, int base) Converts the string pointed to by the argument str converts the string pointed to by base into an unsigned long integer (of type unsigned long int); base must be between 2 and 36 (inclusive), or the special value 0.
Declaration
Below is the declaration of the strtoul() function.
unsigned long int strtoul(const char *str, char **endptr, int base)
Parameters
- str -- The string to be converted to an unsigned long integer.
- endptr -- A reference to an object of type char*, whose value is set by the function to the next character after the numeric value in str.
- base -- The base, which must be between 2 and 36 (inclusive), or the special value 0.
Return Value
This function returns the converted long integer; if no valid conversion was performed, a zero value is returned.
Example
The following example demonstrates the use of the strtoul() function.
#include
#include
int main()
{
char str[30] = "2030300 This is test";
char *ptr;
long ret;
ret = strtoul(str, &ptr, 10);
printf("数字(无符号长整数)是 %lu\n", ret);
printf("字符串部分是 |%s|", ptr);
return(0);
}
Let's compile and run the above program, which will produce the following result:
数字(无符号长整数)是 2030300
字符串部分是 | This is test|
C Standard Library -