C strchr() Function

Last Updated:

C strchr()

The strchr() function determines the first occurrence of the given character in the string.

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

Example

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

Syntax

char *strchr(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 first occurrence of the given character in the given string.
NULL If the character is not found.

Share this Page

Meet the Author