Write a program to compare two strings without using the
strcmp() function
Answer Posted / nomi mayana
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
char a[25],b[25];
int cnt=1,i=1;
cout<<"\n ENTER THE STRING 1 : ";
cin>>a;
cout<<"\n ENTER THE STRING 2 : ";
cin>>b;
while(a[i]!='\0' && b[i]!='\0')
{
if(a[i]==b[i])
{
cnt++;
}
else
{
cout<<"\n\n THE TWO STRINGS ARE NOT EQUAL";
}
i++;
}
if(i==cnt)
{
int n;
cout<<"\n\t\t~~~~~~~~~~COMPARISON RESULT~~~~~~~~~~~";
cout<<"\n THE GIVEN TWO STRINGS ARE SAME ";
}
//getch();
return 0;
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Why doesnt that code work?
What is nested structure with example?
How can you be sure that a program follows the ANSI C standard?
What is a pragma?
Explain null pointer.
Can you please explain the difference between malloc() and calloc() function?
What is difference between structure and union in c programming?
If a five digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits.For example if the number that is input is 12391 then the output should be displayed as 23402
How can I make it pause before closing the program output window?
What is calloc() function?
Is null always equal to 0(zero)?
What does 4d mean in c?
When should you not use a type cast?
Explain how can I make sure that my program is the only one accessing a file?
Difference between MAC vs. IP Addressing