#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<string.h>
class para
{
public: char ckey,skey[10],sent[40];
int i;
void get()
{
cout<<"Type the paragraph of maximum 40 characters, press enter to finish:\n------------------------"<<endl;
gets(sent);
cout<<"---------------------------------------------\nput the letter to be searched:";
cin>>ckey;
cout<<"type the string to be searched:";
gets(skey);
cout<<"processing...\n";
}
void check();
};
void para::check()
{
int l=strlen(sent);
cout<<"\n-------------------------------------\n Length of ur data="<<l;
cout<<" '"<<ckey<<"' is present at the following positions:";
int flagc=0;
int flags=0;
for(i=0;i<l;i++)
{
if(sent[i]==ckey)
{
cout<<" "<<i+1<<"\t";
flagc++;
}
}
if(flagc==0) cout<<endl<<" '"<<ckey<<"' is not present!";
else cout<<endl<<" total occurence ="<<flagc;
cout<<"\n\n--------------------\n\n";
cout<<"The string '"<<skey<<"' starts at the following positions\n";
int j,x,y,t=0;
int lk=strlen(skey);
for(i=0;i<lk;i++)
{
for(j=0;j<l;j++)
{
if(skey[i]==sent[j])
{
x=i;
y=j;
flags=0;
for(x,y;x<lk,y<j+lk;x++,y++)
{
if(skey[x]!=sent[y]) break;
else
{
flags++;
if(flags==lk)
{
cout<<j+1<<"\t";
t++;
}
}
}
}
}
}
cout<<"\n\n total occurence ="<<t;
};
void main()
{
clrscr();
para obj;
obj.get();
obj.check();
getch();
}
Have U tried this?
Comments
Post a Comment