大文字小文字を区別せずに文字列と文字列が同じかどうか比較するにはstrcasecmpを使用します。
以下にstrcasecmpを使用した例を記します。
#include <string.h>
int strcasecmp(const char *s1, const char *s2);
書式を確認すると以下のようになります。
&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;
}
以下にコンパイルおよび実行結果を記します。
$ 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サンプルコードでした。