文字列数値をlong longに変換・atoll †数字文字列をlong long型の数値に変換するatoll関数について記します。 スポンサーリンク 関連記事 †atollの書式 †atollの書式等を以下に記します。
atollを使用したCサンプルコード †以下にatollを使用したCサンプルコードを記します。 #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のCサンプルコードでした。 スポンサーリンク |