C strrchr() Function

Last Updated:

C strrchr()

The strrchr() function determines the last occurrence of the given character in the string.

In the following example, *lName is a pointer variable which collects address returned by strrchr() function.

Example

C Compiler
#include <stdio.h> #include <string.h> int main() { const char str[] = "John Doe R"; const char ch = ' '; char *lName; lName = strrchr(str, ch); printf("Last Name: %s", lName); return 0; }

Syntax

char *strrchr(char *str, int ch)

Parameter Values

ValueTypeExplanation
str Required Specifies a string.
ch Required Specifies a character.

Return Value

ValueExplanation
Address Returns the pointer to a position in the last occurrence of the given character in the given string.
NULL If the character is not found.

Share this Page

Meet the Author