write a C++ program given below?

Muhammad Zafar

New member
Read 2 positive integers from a user, it finds if the smaller (in number of digits)
number is present in the larger number and its indices. For example if user enters
54826827 and 82 then number 82 is present in 5482 at index 2 and 5.


my code is given below: -
#include<iostream>
#include<string>
using namespace std;
int main()
{
int counter=0;
char x[51];
char y[5];
char discard;
cout<<"please enter the number of digits in the number"<<endl;
cin>>counter;
cout<<"please enter the number"<<endl;

for (int i=0;i<counter;i++)
{
cin>>x;
}

cout<<"please enter the integar to be found"<<endl;

for(int j=0;j<=1; j++)
{
cin>>y[j];
}
if (strstr(x, y)) //find y in x
cout << "string found";

//to find out at what index:

char* F = 0;
if (F = strstr(x, y)); //pF points to the first character of y in x
{
int Index = F - x;
cout << "At index:" << Index;
}


return 0;
}

however it isnt giving the rite result...can any1 plz help by writing the write code??
i shall be very thankful to u..
 
Back
Top