Linux C function() 參考手冊:字符串轉換篇-atol(將字串轉換成長整型數)

Linux C function() 參考手冊:字符串轉換篇-atol(將字串轉換成長整型數)

Linux C function() 參考手冊:字符串轉換篇-atol(將字串轉換成長整型數)

 

資料來源:http://people.cs.nctu.edu.tw/~yslin/library/linuxc/main.htm

 

相關函數
atof,atoi,strtod,strtol,strtoul
表頭文件
#include<stdlib.h>
定義函數
long atol(const char *nptr);
函數說明
atol()會掃描參數nptr字符串,跳過前面的空格字符,直到遇上數字或正負符號才開始做轉換,而再遇到非數字或字符串結束時(‘\0’)才結束轉換,並將結果返回。
返回值
返回轉換後的長整型數。
附加說明
atol()與使用strtol(nptr,(char**)NULL,10);結果相同。

線上執行:http://www.tutorialspoint.com/compile_c_online.php
code2html:http://tohtml.com/

 

範例

 

/*將字符串a與字符串b轉換成數字後相加*/
#include <stdio.h>
#include <stdlib.h>
main()
{
char a[]="1000000000";
char b[]="234567890";
long c;
c=atol(a)+atol(b);
printf("c=%d\n",c);
}





 




發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *