strchr()
christian.dinh2476 total contributions
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
All contributors
- christian.dinh2476 total contributions
- Anonymous contributorAnonymous contributor3071 total contributions
- Anonymous contributorAnonymous contributor24 total contributions
- christian.dinh
- Anonymous contributor
- Anonymous contributor
Looking to contribute?
- 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.