Dotcpp  >  编程教程  >  stdlib.h头文件  >  C语言atol()函数:将字符串转换成长整型数

C语言atol()函数:将字符串转换成长整型数

点击打开在线编译器,边学边练

函数名:atol

头文件:<stdlib.h>

函数原型: int atol(const char *s);

功能: 将字符串转换成长整型数

参数:const char *s  为要转换的字符串 

返回值:返回转换后的长整型值


程序例:将字符串"525713.14"转换成长整型,并输出字符串和转换的长整型

#include<stdio.h>

#include<stdlib.h>

int main(void){

   long r;

   char *s="525713.14";

   r=atol(s);

   printf("string = %s\nint= %ld\n",s,r);

   return 0;

}

 

运行结果

string = 525713.14
int= 525713



本文固定URL:https://www.dotcpp.com/course/545

C语言函数库
assert.h头文件
ctype.h头文件
float.h头文件
io.h头文件
math.h头文件
mem.h头文件
setjmp.h头文件
stdio.h头文件
stdlib.h头文件
sigal.h头文件
string.h头文件
time.h头文件
Dotcpp在线编译      (登录可减少运行等待时间)