C strstr

The strstr() function returns pointer to the first occurrence of the matched string in the given string. It is used to return substring from first match till the last character.

Syntax

  strstr(string,match)  

where

string: It represents the full string from where substring will be searched.

match: It represents the substring to be searched in the full string.

 

 Example

    #include<stdio.h>  
    #include <string.h>    
    int main(){    
      char str[100],target[100];
      printf("\n Input a string:");
      gets(str);  
      char *sub;
      printf("\n Matched string: ");
      gets(target);  
      sub=strstr(str,target);    
      printf("\nSubstring is: %s",sub);    
     return 0;    
    }     

Output

No comments:

Post a Comment