数字文字列をlong long型の数値に変換するatoll関数について記します。
c-top.html is not found or not readable.atollの書式等を以下に記します。
#include <stdlib.h>
long long atoll(const char *nptr);
以下にatollを使用したCサンプルコードを記します。
&ref(): File not found: "atoll.c" at page "数値/文字列数字をlong longに変換・atoll"; (改行コード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サンプルコードでした。
c-btm.html is not found or not readable.