C 库函数 long int strtol(const char *str, char **endptr, int base)
把参数 str 所指向的字符串根据给定的 base 转换为一个长整数(类型为 long int 型),base 必须介于 2 和 36(包含)之间,或者是特殊值 0。
code:
#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);
}
result:
数字(无符号长整数)是 2030300 字符串部分是 | This is test|
原文:https://www.cnblogs.com/lianghong881018/p/12191547.html