The strstr() function is defined in the string.h header file. It helps to returns a pointer to the first occurrence of the matched substring in the given full string pointed by 'string'.
char *strstr(const char *string, const char *match) ; #where string and match should be strings
The strstr() function takes two parameters.
Parameter | Description | Required / Optional |
---|---|---|
string | the full string from where substring will be searched | Required |
match | the substring to be searched in the full string | Required |
The function returns a pointer to the first occurrence in a full string of any of the entire sequence of characters specified in the match.
Input | Return Value |
---|---|
if parameters | pointer to first occurrence of match string |
#include <stdio.h>
#include <string.h>
int main()
{
char string[100]="this is javatpoint with c and java";
char *s;
s=strstr(string,"java");
printf("\nThe substring is: %s",s);
return 0;
}
Output:
javatpoint with c and java
#include <stdio.h>
#include <string.h>
int main (){
const char fulstrng[20] = "TutorialsPoint";
const char substrng[10] = "Point";
char *out;
out = strstr(fulstrng, substrng);
printf("The substring is: %s\n", out);
return(0);
}
Output:
The substring is: Point