hi ,
i have written a program which recieves 2 strings and checks (is the second string "hasEndig" with 1 strings or not !)
for example : when we input strings : 1.Hello / 2.ello , it should return 1(TRUE) , and so on ...
this is the Code i've written ... i think my algorithm is correct but ... The program doesn't work Correctly ...!!
do u Know my algorithm ? if u didn't recognize , i can explain my algorithm ... thanks
Code:
#include <iostream>
using namespace std;
bool hasEnding(char str1[],int size1,char str2[],int size2){
if (size2>size1)
return false;
for (int i=0 ; i<size1 ; i++)
for (int j=0 ; j<size2 ; j++){
while (str1[i]==str2[j] && j<size2){
i++;
j++;
if (str1[i]!=str2[j])
return false;
}
return true;
}
}
int main(){
char string1[100],string2[100];
cout << "Enter 1st String :\t";
cin.get(string1,'0');
cout << "Enter 2nd String:\t";
cin>>ws;
cin.get(string2,'0');
int size1,size2;
for (size1=0 ; size1<100 ; size1++){
if (string1[size1]==0)
break;
}
for (size2=0 ; size2<100 ; size2++){
if (string2[size2]==0)
break;
}
cout << "The 2nd string is repeated in 1st string ?? " <<endl;
cout << "RESULT : \t " << hasEnding(string1,size1,string2,size2)<<endl;
system("pause");
return 0;
}