< 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 parameters 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 */


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

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 -

< Prev
Next >
< Reading String from Console
C strlen() function >


Please Subscribe

Please subscribe to our social media channels for daily updates.

Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page



Please check our latest addition