About cookies on this site Our websites require some cookies to function properly (required). In addition, other cookies may be used with your consent to analyze site usage, improve the user experience and for advertising. For more information, please review your options. By visiting our website, you agree to our processing of information as described in IBM’sprivacy statement. To provide a smooth navigation, your cookie preferences will be shared across the IBM web domains listed here.
strchr() — Search for Character
Last Updated: 2025-10-07
Format
Language Level
ANSI
Threadsafe
Yes
Locale Sensitive
The behavior of this function might be affected by the LC_CTYPE category of the current locale. For more information, see Understanding CCSIDs and Locales.
Description
The strchr() function
finds the first occurrence of a character in a string. The character c can
be the null character (\0); the ending null character of string is
included in the search.
The strchr() function
operates on null-ended strings. The string arguments to the function
should contain a null character (\0) that marks the end of
the string.
Return Value
The strchr() function
returns a pointer to the first occurrence of c that
is converted to a character in string. The
function returns NULL if the specified character is not found.
Example
This example finds the first occurrence
of the character
“p”in
“computer program”.
Related Information
- strcat() — Concatenate Strings
- strcmp() — Compare Strings
- strcpy() — Copy Strings
- strcspn() — Find Offset of First Character Match
- strncmp() — Compare Strings
- strpbrk() — Find Characters in String
- strrchr() — Locate Last Occurrence of Character in String
- strspn() — Find Offset of First Non-matching Character
- wcschr() — Search for Wide Character
- wcsspn() — Find Offset of First Non-matching Wide Character
- <string.h>