Thread: [Help]C++
View Single Post
Old 11-16-2010   #4
ZC
Registered Member
 
ZC's Avatar
 
Last Online: 07-15-2013
Join Date: Aug 2006
Posts: 100
Thanks: 13
Thanked 24 Times in 24 Posts
Groans: 0
Groaned at 0 Times in 0 Posts
Default

A program that checks if a string is a substring of another....!

#include<iostream>
using namespace std;
#include<cstring>
int main()
{

char a[100];
char b[50];
int i=0;
int j=0;
int lb=strlen(b);
int la=strlen(a);
bool is=false;
cout<<"please input a string"<<endl;
cin.get(a,100);
char garbage;
cin.get(garbage);
cout<<"now enter a string to check if it is a substring"<<endl;
cin.get(b,50);
while(la>=lb&&a[i]!='\0')
{
if(a[i]==b[j])
{i++;
j++;
is=true;}
if(a[i]!=b[j])
{i++;
is=false;
j=0;}

}


if(is=true)
cout<<"yes"<<endl;
if(is=false)
cout<<"no"<<endl;
}
__________________
Books all say different things while people flap their yellow wings trying
to soar by being a whore of life!!!!




ZC is offline   Reply With Quote