COMPARISION OF STRINGS WITHOUT PREDEFINED STRING FUNCTION


#include<iostream>
#include<string>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
string s1,s2;
cout<<"enter a string s1 "<<endl;
cin>>s1;
cout<<endl<<"enter string s2 "<<endl;
cin>>s2;
int a;
int z=s1.length();
int y=s2.length();
if(z<=y){
a=s1.length();
}
else{

a=s2.length();
}
int count=0;
for(int x=0;x<a;x++){
if(s1[x]==s2[x]){
count++;
}
}
if(count==a){
cout<<"strings matched "<<endl;
}
else{
cout<<"strings didnot match "<<endl;
}

}



Previous
Next Post »

Comments:

Disqus Shortname