Write a C++ program to compare two strings they are exact equal or not.
Program Code:
#include<iostream>
using namespace std;
int main( )
{
int i;
char name1[30], name2[30];
cout<<"Enter your first string: ";
cin.getline(name1, 30);
cout<<endl;
cout<<"Enter your second string: ";
cin.getline(name2, 30);
cout<<endl;
for (i = 0; name1[i] == name2[i] && name1[i]!= '\0' && name2[i] != '\0'; i++);
if(name1[i] - name2[i] == 0)
{
cout << "Strings are equal";
}
else
{
cout << "Strings are not equal";
}
return 0;
}
This program output is tested on www.jdoodle.com
Output:
Enter your first string: abc
Enter your second string: xyz
Strings are not equal
Thanks
Mukesh Rajput
Post A Comment:
0 comments: