Table of contents
What is strchr in c programming?
strchr in c is a built-in function used to search for a first occurrence of the given character in a string.
This function is defined in string.h header file.
strchr function returns first occurrence of the character in a string else null if character not found.
Prototype
char *strchr(const char *string,int m);
Parameters
strchr function takes one pointer and integer variable as input parameters.
Return value
strchr function returns first occurrence of a character in a string else null if not found.
Example program for strchr
#include<stdio.h>
#include<string.h>
int main()
{
const char string[]="scholarsoul";
const char a='o';
char *res;
res=strchr(string,a);
printf("The first occurrence of given character is %s \n",res);
return 0;
}
The first occurrence of given character is olarsoul
Code explanation
The first occurrence of a given character is found by calling strchr function and result is being printed on to console.
People also ask for
What is strchr?
strchr is a built-in function used to search for a first occurrence of the given character in a string. It is defined in string.h header file.
People also read
strcat()
function in c.strlen()
function in c.strncat()
function in c.strcmp()
function in c.- String functions.