Anonymous contributors
Anonymous contributors
Published Aug 25, 2021Updated Dec 20, 2021
Contribute to Docs

The strchr() string function finds the first occurrence of a given character.


The string.h header file needs to be included at the top of the file:

#include <string.h>

strchr() function searches string for the character 'c':

strchr(string, 'c')


Using strchr() function to find a specific character in the alphabet:

#include <stdio.h>
#include <string.h>
int main() {
char alphabet[] = "abcdefghijklmnopqrstuvwxyz";
printf("%s", strchr(alphabet, 's'));
return 0;

The output would be:


All contributors

Looking to contribute?

Learn C on Codecademy