XINU
Functions
strstr.c File Reference

検索対象の文字列Aから文字列Bを探す。 More...

Go to the source code of this file.

Functions

char * strstr (const char *cs, const char *ct)
 検索対象の文字列Aから文字列Bを探す。 More...
 

Detailed Description

検索対象の文字列Aから文字列Bを探す。

Definition in file strstr.c.

Function Documentation

◆ strstr()

char* strstr ( const char *  cs,
const char *  ct 
)

検索対象の文字列Aから文字列Bを探す。

Parameters
[in]cs検索対象の文字列
[in]ct検索語句(検索キーワード)となる文字列
Returns
検索語句が見つかった場合はその位置をポインタで返し、見つからなかった場合はNULLを返す。

Definition at line 12 of file strstr.c.

13 {
14  char *cq;
15  char *cr;
16 
17  for (; *cs != '\0'; cs++)
18  {
19  if (*cs == *ct)
20  {
21  cq = (char *)cs;
22  cr = (char *)ct;
23  while ((*cq != '\0') && (*cr != '\0'))
24  {
25  if (*cq != *cr)
26  {
27  break;
28  }
29  cq++;
30  cr++;
31  }
32  if ('\0' == *cr)
33  {
34  return (char *)cs;
35  }
36  }
37  }
38  return 0;
39 }