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

英字かどうかをチェックする・isalpha

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

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

関連記事

isalpha関数の書式等

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

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

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

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

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

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

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

    return 0;
}

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

$ gcc isalpha.c -o isalpha
$ ./isalpha 
ascii[0] = A is alphabet.
ascii[1] = B is alphabet.
ascii[2] = ? is *not* alphabet.
ascii[3] = # is *not* alphabet.
ascii[4] = 1 is *not* alphabet.
ascii[5] = 2 is *not* alphabet.
ascii[6] = a is alphabet.
ascii[7] = b is alphabet.

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

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

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