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
while initialization of array why we use a[][2] why not a[2][]...?
Is anything faster than c?
How can a program be made to print the line number where an error occurs?
Explain what are header files and explain what are its uses in c programming?
How do you do dynamic memory allocation in C applications?
i want to know the procedure of qualcomm for getting a job through offcampus
write a program to find the given number is prime or not
Differentiate between declaring a variable and defining a variable?
Why c is a mother language?
Is file a keyword in c?
What Is The Difference Between Null And Void Pointer?
What is ambagious result in C? explain with an example.
Why is it that not all header files are declared in every C program?
What are the different types of constants?
What is Dynamic memory allocation in C? Name the dynamic allocation functions.