- 追加された行はこの色です。
- 削除された行はこの色です。
#navi(../)
* 文字列数値をlong longに変換・atoll [#x273b1a6]
数字文字列をlong long型の数値に変換するatoll関数について記します。
#contents
#htmlinsertpcsp(c-top.html,c-sp.html)
* 関連記事 [#p471e66a]
-[[文字列数字をintに変換・atoi>数値/文字列数字をintに変換・atoi]]
-[[文字列数字をlongに変換・atol>数値/文字列数字をlongに変換・atol]]
-[[文字列数字をlong longに変換・atoll>数値/文字列数字をlong longに変換・atoll]]
-[[文字列数字をdoubleに変換・atof>数値/文字列数字をdoubleに変換・atof]]
* atollの書式 [#l50a581e]
atollの書式等を以下に記します。
- 必要なインクルードファイル
#include <stdlib.h>
-書式
long long atoll(const char *nptr);
* atollを使用したCサンプルコード [#j9b43f34]
以下にatollを使用したCサンプルコードを記します。~
&ref(atoll.c); (改行コードLF)
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
long long i,j,k,l;
i = atoll("987654321987654321");
j = atoll("abcdeghij");
k = atoll("998877665544332211abcdef");
l = atoll("999.999");
printf("i = %lld\n", i);
printf("j = %lld\n", j);
printf("k = %lld\n", k);
printf("l = %lld\n", l);
return 0;
}
コンパイルして実行した時の結果を以下に記します。
$ gcc atoll.c -o atoll
$ ./atoll
i = 987654321987654321
j = 0
k = 998877665544332211
l = 999
サンプルコードでは、数値以外の文字列、後方が数字以外の文字列、小数点を含む文字列を対象にatoll関数を実行しました。~
各出力を確認しatollの動作を理解してください。
以上、atollのCサンプルコードでした。
#htmlinsertpcsp(c-btm.html,c-sp.html)