C strchr()
Anonymous contributor
Published Aug 25, 2021Updated Dec 20, 2021
Contribute to Docs
The strchr() string function finds the first occurrence of a given character.
Syntax
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')
Example
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:
stuvwxyz
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn C on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours