目录

long int atol(const char *str)

描述 (Description)

C库函数long int atol(const char *str)将字符串参数str转换为长整数(类型为long int)。

声明 (Declaration)

以下是atol()函数的声明。

long int atol(const char *str)

参数 (Parameters)

  • str - 这是包含整数表示的字符串。

返回值 (Return Value)

此函数将转换后的整数作为long int返回。 如果无法执行有效转换,则返回零。

例子 (Example)

以下示例显示了atol()函数的用法。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main () {
   long val;
   char str[20];
   strcpy(str, "98993489");
   val = atol(str);
   printf("String value = %s, Long value = %ld\n", str, val);
   strcpy(str, "iowiki.com");
   val = atol(str);
   printf("String value = %s, Long value = %ld\n", str, val);
   return(0);
}

让我们编译并运行上面的程序,这将产生以下结果 -

String value = 98993489, Long value = 98993489
String value = iowiki.com, Long value = 0
↑回到顶部↑
WIKI教程 @2018