[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.

Program Discussion :: Strings

Home > Programs > Strings

85 / 60

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: