
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
strchr Function in C/C++
The function strchr() is used to search the character in the string. It search the first occurrence of character which is passed as second argument and it returns a pointer to the character, if successful otherwise, NULL.
Here is the syntax of strchr() in C language,
char *strchr(const char *string , int character)
Here,
string − The string which is to be scanned to search the character.
character − The character which is to be searched in the string.
Here is an example of strchr() in C language,
Example
#include<stdio.h> #include<string.h> int main() { char s[] = "Helloworld!"; char c = 'o'; char *result = strchr(s, c); printf("String after searching the character : %s", result); return 0; }
Output
String after searching the character : oworld!
In the above program, a char type string is passed and a character which is to be searched in the string. The result is stored in pointer variable *result.
char s[] = "Helloworld!"; char c = 'o'; char *result = strchr(s, c);
Advertisements