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

大文字小文字を区別せずに文字列同士を比較する・strcasecmp

大文字小文字を区別せずに文字列と文字列が同じかどうか比較するにはstrcasecmpを使用します。
以下にstrcasecmpを使用した例を記します。

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

関連記事

strcmpの書式

書式を確認すると以下のようになります。

strcasecmpのCサンプルコード

&ref(): File not found: "strcasecmp.c" at page "文字列/大文字小文字を区別せずに文字列同士を比較する・strcasecmp"; (改行コードLF)

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

int main(void)
{
    char *a = "abcdefg";
    char *b = "AbCdEfG";
    char *c = "ABCDEFG";

    if (0 == strcasecmp(a, b)) {
        printf("strcasecmp(a, b) : a and b are the same.\n");
    }
    else {
        printf("strcasecmp(a, b) : a and b are different.\n");
    }

    if (0 == strcasecmp(b, c)) {
        printf("strcasecmp(b, c) : a and b are the same.\n");
    }
    else {
        printf("strcasecmp(b, c) : a and b are different.\n");
    }

    return 0;
}

strcasecmpのCサンプルコード実行結果

以下にコンパイルおよび実行結果を記します。

$ gcc strcasecmp.c -o strcasecmp
$ ./strcasecmp 
strcasecmp(a, b) : a and b are the same.
strcasecmp(b, c) : a and b are the same.

以上、strcasecmpのCサンプルコードでした。

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

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