strstr() 関数のように、大文字と小文字を無視する 質問する

strstr() 関数のように、大文字と小文字を無視する 質問する

文字列が2つあります。`

str1="One Two Three";

そして

str2="two";

最初の文字列と 2 番目の文字列の一致をチェックし、最初の出現箇所へのポインターを返す関数があるかどうかを知りたいのですが、strstr()大文字または小文字の同じ文字を 2 つの異なる文字として扱いません。

私の例では、のstr2大文字の にもかかわらず、関数は最初の文字列で の一致を見つける必要があります。"T""Two"

ベストアンサー1

のマニュアルページからstrstr:

STRSTR(3)           Linux Programmer's Manual           STRSTR(3)

NAME
       strstr, strcasestr - locate a substring

SYNOPSIS
       #include <string.h>

       char *strstr(const char *haystack, const char *needle);

       #define _GNU_SOURCE

       #include <string.h>

       char *strcasestr(const char *haystack, const char *needle);

DESCRIPTION
       The  strstr()  function  finds the first occurrence of the substring needle in
       the string haystack.  The terminating '\0' characters are not compared.

       The strcasestr() function is like strstr(3), but  ignores  the  case  of  both
       arguments.

RETURN VALUE
       These functions return a pointer to the beginning of the substring, or NULL if
       the substring is not found.

つまり、あなたが探しているのは ですstrcasestr

おすすめ記事