Take FREE!! Online AMCAT Mock Test to Crack Wipro NLTH, Capgemini, etc.
Get Off-Campus Placement Jobs Info !!!
Practice Given Here Wipro NLTH Practice Q&A

Program Discussion :: Strings

Home > Programs > Strings

6 / 59

Given a pattern and a text, write a program to check whether the pattern is present in the text

Answer:

#include
#include
using namespace std;
int main()
{
    int i,j,temp;
    char str[100]={"This is a pattern matching"};
    char substr[20]={"pattern"};
    for(i=0;str[i]!='\0';i++)
    {
        j=0;
        if(str[i]==substr[j])
        {
            temp=i+1;
            while(str[i]==substr[j])
            {
                i++;
                j++;
            }
 
            if(substr[j]=='\0')
            {
                cout

Asked In :: Aricent

Post Your Answer Here:

Language:

Post Your Reply Here:



Language:

Post Your Reply Here: