C strstr()

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


strstr() Parameters: 

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

strstr() Return Value

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

Examples of strstr() 

Example 1: Working of strstr() function in C?

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

int main()
   char string[100]="this is javatpoint with c and java";    
  char *s;    
  printf("\nThe substring is: %s",s);    
 return 0;    



javatpoint with c and java

Example 2: How strstr() works in C?

#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);


The substring is: Point