C library functions - strrchr ()
C standard library - <string.h>
description
C library functionschar * strrchr (const char * str , int c) in the parameter strpoints to the string to search for the last occurrence of characterc (anunsigned character) position.
statement
Here is () statement strrchr function.
char *strrchr(const char *str, int c)
parameter
- str - C string.
- c - the character to be searched.Passing an int, but will eventually be converted back to a char.
return value
This function returns the position of the last character in str c appears. If the value is not found, the function returns a null pointer.
Examples
The following example demonstrates strrchr () function is used.
#include <stdio.h> #include <string.h> int main () { int len; const char str[] = "http://www.w3cschool.cc"; const char ch = '.'; char *ret; ret = strrchr(str, ch); printf("|%c| 之后的字符串是 - |%s|\n", ch, ret); return(0); }
Let's compile and run the above program, which will result in the following:
|.| 之后的字符串是 - |.cc|