C库函数long int atol(const char *str) 将字符串参数str转换为长整数(类型long int)。
声明
以下是atol函数的声明。
longintatol(constchar*str)
参数
str - 这是包含整数表示的字符串。
返回值
此函数将转换后的整数返回为long int。如果无法执行有效的转换,它将返回零。
示例
以下示例显示atol函数的用法-
#include<stdio.h>#include<stdlib.h>#include<string.h>intmain(){long val;char str[20];strcpy(str,"98993489");
val =atol(str);printf("String value = %s, Long value = %ld\n", str, val);strcpy(str,"jc2182.com");
val =atol(str);printf("String value = %s, Long value = %ld\n", str, val);return(0);}