Well I wrote this program which checks if a string is present in another string
example : say 1st string is "COMPUTER"
2nd string is "PUT"
then basically its present .... I wrote the following program but Im getting epic fail ... D: ... please help me spot my mistake <.> .
example : say 1st string is "COMPUTER"
2nd string is "PUT"
then basically its present .... I wrote the following program but Im getting epic fail ... D: ... please help me spot my mistake <.> .
Code:
#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
int check(string s1,string s2)
{
int c=0;
int x=s1.length();
for(int i=0;i<20;i++)
{
if(s1[i]==s2[0])
{
c=i;
for(int j=0;j<x;j++)
{
if(s1[c]!=s2[j])
{
return 0;
}
c++;
}
}
}
return 1;
}
void main()
{
string s1="";
string s2="";
int x=0;
cout<<"Enter 1st string";
getline(cin,s1);
cout<<"Enter 2nd string";
getline(cin,s2);
x=check(s1,s2);
if(x==1)
{
cout<<"OMG WOOT !!!";
}
else
cout<<"EPIC FAIL !!!";
}