
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
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);
- Related Articles
- strchr() Function in C++
- strchr() function in C++ and its applications
- strchr() function in PHP
- iswblank() function in C/C++
- iswpunct() function in C/C++
- strtod() function in C/C++
- memmove() function in C/C++
- memcpy() function in C/C++
- atexit() function in C/C++
- raise() function in C/C++
- mbrlen() function in C/C++
- strftime() function in C/C++
- iswlower() function in C/C++
- towupper() function in C/C++
- iswdigit() function in C/C++

Advertisements