C String – strchr() function1 min read

strchr() function in C is used to search the stated character in a string.

It searches the string for the character and stops when the first time the character is found. And if the string needs to be printed, only the character starting from the searched character to the end is printed.

The strchr() function is defined in the header file string.h.

It takes two arguments, first the string name and another is the character you need to search in the string and is written as follows.

strchr(string_name, search_Char);

C Program for strchr() function

Output:

Searched Character is s, So:
site is simple2code.com

First-time s is found in ‘website’, so the character after s that is “site is simple2code.com” is printed.


C String – strrchr() function

strrchr() function is also the same as the strchr() function only difference is that it starts the search in reverse order and stops when the searched character is found.

C Program for strrchr() function

Output:

Searched Character is s, So:
simple2code.com

Searching from the reverse order the program finds the first ssimple2code.com’, so the character after s that is “simple2code.com” is printed.


MORE

Implement Insertion sort Program in C

In this tutorial, we will learn and write a C program to implement insertion sort. Before that you may go through the following topics in …
Read More

C Program for implementation of Selection sort

In this tutorial, we will learn and write a C program to implement selection sort using function. Before that you may go through the following …
Read More

C Program to Delete a Particular element from an Array

In this tutorial, we will write a C program to delete an element in an array by specifying the value. Before that, you should have …
Read More

C Program to sort a String in Ascending order

In this tutorial, we will write a c program to sort a string array in ascending order. Before that, you may go through the following …
Read More

C Program to find Maximum occurring Character in a String

In this tutorial, we will write a program in C to find the maximum occurring character in a string. Before that, you may go through …
Read More

Keith Number Program in C

In this tutorial, we will write a Keith number in C. It is one of the most asked questions in an interview. Before that, you …
Read More