Table of contents
strstr function in c
strstr function searches for a given string in the main string.
It returns a pointer to the first occurrence of a given string.
It is defined in string.h header file.
Prototype
char *strstr(const char *string,const char *searchstr);
Parameters
This function takes searching string and main string as input characters.
Return value
This function returns a pointer to the first occurrence of a given string.
strstr in c example
//strstr c implementation
#include<stdio.h>
#include<string.h>
int main()
{
const char string[20]="soul";
const char search[30]="scholarsoul";
char *res;
res=strstr(string,search);
printf("Result is %s \n",res);
return 0;
}
Output
Result is soul
Code explanation
strstr function is called by passing search string and main string. The result is being printed on to the console.
People also ask for
What is strstr in c?
strstr function searches for a given string in a main string. It is defined in string.h header file.
People also read
- String in c programming
- C pointers
- strchr in c
- strtol in c
- strtod in c
- Popular c functions upgrad
- strncpy in c
- strcpy in c
- strcmp in c
- strrev in c
- strrchr in c