strstr() string handling functions - C-Tutorial

Latest

Friday, 7 October 2016

strstr() string handling functions

strstr() function


  • ·         Function is used to search one string into another string.
  • ·         Function accepts two strings (OriginalString and SearchString) as an argument. It returns NULL if search string is not found in Original String.
  •                                     
  •                                           Syntax:

strstr (OriginalString, SearchString);



#include <stdio.h> 
#include <conio.h> 
#include <string.h> 
void main () 
{ 
    char s1[20],s2[20]; 
    clrscr (); 
    puts(“Enter Original String”); 
    gets(s1); 
    puts(“Enter Search String”); 
    gets(s2); 
    if ( strstr(s1, s2)==NULL) 
    printf (“String Not Found");
    else
    printf (“String Found”);
    getch (); 
}

No comments:

Post a Comment