C library functions - strtoul ()
C standard library - <stdlib.h>
description
C library functionsunsigned long int strtoul (const char * str, char ** endptr, int base) the argument strpoints to the string according to the givenbaseis converted to an unsigned long integer (unsigned long int type type), base must be between 2 and 36 (inclusive), or the special value 0.
statement
The following is a statement strtoul () function.
unsigned long int strtoul(const char *str, char **endptr, int base)
parameter
- str - a string to be converted to non-unsigned long integer.
- A reference to an object of type char *, and its value is set by the function value in str after the next character- endptr.
- base - base must be between 2 and 36 (inclusive), or the special value 0.
return value
This function returns the converted long integer if there is no implementation of an effective conversion, it returns a value of zero.
Examples
The following example demonstrates strtoul () function is used.
#include <stdio.h> #include <stdlib.h> 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 result in the following:
数字(无符号长整数)是 2030300 字符串部分是 | This is test|