XINU
Functions
strrchr.c File Reference

指定された文字を文字列から探し、最後に見つかった位置をポインタで返す。 More...

Go to the source code of this file.

Functions

char * strrchr (const char *s, int c)
 文字列の後方から指定された文字を探し、最後に見つかった位置をポインタで返す。 More...
 

Detailed Description

指定された文字を文字列から探し、最後に見つかった位置をポインタで返す。

Definition in file strrchr.c.

Function Documentation

◆ strrchr()

char* strrchr ( const char *  s,
int  c 
)

文字列の後方から指定された文字を探し、最後に見つかった位置をポインタで返す。

Parameters
[in]s探索対象の文字列
[in]c検索文字
Returns
文字cが見つかった場合は文字cが最後に登場した位置を示すポインタ、
文字cが見つからなかった場合はNULLを返す。

Definition at line 13 of file strrchr.c.

14 {
15  char *r = 0;
16 
17  for (; *s != '\0'; s++)
18  {
19  if (*s == (const char)c)
20  {
21  r = (char *)s;
22  }
23  }
24 
25  if ((const char)c == *s)
26  {
27  return (char *)s;
28  }
29 
30  return r;
31 }