#navi(contents-page-name): No such page: 文字列

数値文字列かどうかをチェックする・isdigit

isdigit関数を使うことにより、引数で渡した文字が数値であるかどうかをチェックすることができます。
以下にisdigit関数を使用したC言語サンプルコードと実行結果を記します。

c-top.html is not found or not readable.

関連記事

isdigit関数の書式等

isdigit関数の書式は以下の通りです。

isdigit関数を使用したサンプルコード

以下にisdigit関数を使用したC言語サンプルコードを記します。
また実行結果も記します。

&ref(): File not found: "isdigit.c" at page "文字列/数値文字列かどうかをチェックする・isdigit"; (改行コードLF)

#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void)
{
    char *ascii = "?#12ab";
    int i;

    for (i=0; i<strlen(ascii); i++) {
        if (isdigit(ascii[i])) {
            printf("ascii[%d] = %c is digit.\n", i, ascii[i]);
        } else {
            printf("ascii[%d] = %c is *not* digit.\n", i, ascii[i]);
        }
    }

    return 0;
}

上記のC言語サンプルコードをコンパイルし、実行した時の結果を以下に記します。

$ gcc isdigit.c -o isdigit
$ ./isdigit 
ascii[0] = ? is *not* digit.
ascii[1] = # is *not* digit.
ascii[2] = 1 is digit.
ascii[3] = 2 is digit.
ascii[4] = a is *not* digit.
ascii[5] = b is *not* digit.

以上、isdigit関数を使用したCサンプルコードでした。

c-btm.html is not found or not readable.

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS