C 库函数 - strtol()
C 语言教程
· 2019-02-24 06:43:49
描述
C 库函数 long int strtol(const char *str, char **endptr, int base) 把参数 str 所指向的字符串根据给定的 base 转换为一个长整数(类型为 long int 型),base 必须介于 2 和 36(包含)之间,或者是特殊值 0。
声明
下面是 strtol() 函数的声明。
long int strtol(const char *str, char **endptr, int base)
参数
- str -- 要转换为长整数的字符串。
- endptr -- 对类型为 char* 的对象的引用,其值由函数设置为 str 中数值后的下一个字符。
- base -- 基数,必须介于 2 和 36(包含)之间,或者是特殊值 0。
返回值
该函数返回转换后的长整数,如果没有执行有效的转换,则返回一个零值。
实例
下面的实例演示了 strtol() 函数的用法。
#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); }
让我们编译并运行上面的程序,这将产生以下结果:
数字(无符号长整数)是 2030300 字符串部分是 | This is test|
点击查看所有 C 语言教程 文章: https://www.codercto.com/courses/l/17.html
PHP Cookbook
Adam Trachtenberg、David Sklar / O'Reilly Media / 2006-08-01 / USD 44.99
When it comes to creating dynamic web sites, the open source PHP language is red-hot property: used on more than 20 million web sites today, PHP is now more popular than Microsoft's ASP.NET technology......一起来看看 《PHP Cookbook》 这本书的介绍吧!