C library functions - strtol ()
C standard library - <stdlib.h>
description
C library functionslong int strtol (const char * str , char ** endptr, int base) the argument strpoints to the string according to the givenbaseis converted to a long integer (type long int type), base must be between between 2 and 36 (inclusive), or the special value 0.
statement
The following is a statement strtol () function.
long int strtol(const char *str, char **endptr, int base)
parameter
- str - a string to be converted to a long integer.
- A reference to an object of type char *, and its value is set by the function valuein 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 the strtol () function is used.
#include <stdio.h> #include <stdlib.h> int main() { char str[30] = "2030300 This is test"; char *ptr; long ret; ret = strtol(str, &ptr, 10); printf("数字(无符号长整数)是 %ld\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|