Program to find s2 in s1 where s1 is the main string and s2 is substring


#include<iostream.h>
#include<string.h>
#include<conio.h>
#include<stdio.h>
    void  main ( )
    {
        char s [ 20 ], s1 [ 20 ], s2 [ 20 ], *p = "  " ;
        int i ;
        clrscr();
        cout<< "\n Input string :" ;
        gets ( s );
           cout<< "\n Enter second string " ;
           gets ( s2 );
           strcpy ( s1, s );
        p = strtok ( s2, "  "  ) ;
          for ( i = 0; p ; i ++ )
        {
            if ( strcmp ( p, s2 ) == 0 )
                cout << "\n string found " ;
            p = strtok ( NULL, "  "  ) ;
        }
        getch ( ) ;
    }

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|