< Prev
Next >



C strchr() function




As per the name of the method goes, strchr() function is one of the string handling library functions. The function strchr() is used to search for a particular char value in the target string. Both the char value and string is passed to this function. Let' see the signature of this function.



Signature of strchr()


char *strchr(const char *str, int c)

Looking at the signature of strchr() function, it is passed two paramaters when it is called, where -





Here in the next code, we are going to use strchr() function to search a string for a char value with multiple occurrences and we will see what happens in this case.
/* Program to find a character in a string, with multiple occurrences */


#include<stdio.h>
#include<string.h>

int main()
{
char arr[] = "a beautiful sky";
char ch = 'e';

char *p = strchr(arr,ch); /* it prints the string after the searched char value*/
 
printf("String to be searched for a value : %s  \n", arr);
printf("char value to be searched in String : %c  \n", ch);
printf("Result of search : % s",p);

return 0;
}




Output is :


String to be searched for a value : a beautiful sky
char value to be searched in String : u
Result of search : utiful sky


Program Analysis





Please share this article -

Facebook Google Pinterest Reddit Tumblr Twitter



< Prev
Next >
< Reading String from Console
C strlen() function >
Please subscribe our social media channels for notifications, we post a new article everyday.

Decodejava Google+ Page Decodejava Facebook Page  DecodeJava Twitter Page

Coming Next
-
C++ and Python

Ad2