Problem:- Write A C++ Program To Compare Two String Are Equal Or Not Without Using Library Function or c++ program to compare two strings without using strcmp or C Program to Compare Two Strings without using strcmp function or C Program to Compare Two Strings Without Using strcmp or C program to compare two strings or How to compare two strings in c without using strcmp or Program to Compare Two Strings without using strcmp() in C++ or Write a program to compare two strings without using the strcmp() function or compare two strings without using strcmp in C++
Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.
Logic:- In this problem, you can use two methods one is using library function secondly is without using a library function, but we use here without using a strcmp() function in this we first calculate the size of a both string and if the size of both strings is not equal then program print the message "Both strings are not equal" and if the size of both stings is equal then program compare both string character by character and return if both string is equal or not according to the string analysis. Below is both method for comparing a string using library function or without using library functions.
Using Library Function
strcmp(string1 ,string2)
Without Using Library Function
for(i=0,j=0;str1[i]!='\0',str2[j]!='\0';i++,j++)
{
if(str1[i]==str2[j])
{
flag=1;
}
else
{
flag=0;
}
}
This is a condition is used when the size of both strings is equal and we have to compare both the string character by character.
Sponsor: Install and access your important work applications and software no matter where you from any device ( PC / Android / iOS ) with a cloud desktop from www.CloudDesktopOnline.com. For cloud-related business software such as SharePoint, Office365, try Apps4Rent.
Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post or if you have any Query you can ask there with lots of coders also suggest to your Friends to join and like our page.
Try Yourself - C++ Program To Check String Is Palindrome Or Not
Solution:-
Output:-
You May Also See
1. C Program To Find Character Is Vowel Or Not
2. C Program To Calculate Factorial Of A Given Number
3. C Program To Read Integer (N) And Print First Three Powers (N^1, N^2, N^3)
4. C++ Program To Check Number Is Even Or Odd Using If/Else Statements
5. C++ Program To Check Number Is Prime Or Not Using If/Else Statements
6. C++ Program To Check Character Is Uppercase, Lowercase Alphabet Or A Digit Or A Special Symbol Using If/Else Statements
7. C++ Program To Find Quotient And Reminder Of Two Numbers Using If/Else Statements
8. Java Program To Check Character Is Uppercase, Lowercase Alphabet Or A Digit Or A Special Symbol
9. Java Program To Find Greatest Among Three Numbers
10. Java Program For Find The Salary Of An Employee With Employee Grade
Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.
Logic:- In this problem, you can use two methods one is using library function secondly is without using a library function, but we use here without using a strcmp() function in this we first calculate the size of a both string and if the size of both strings is not equal then program print the message "Both strings are not equal" and if the size of both stings is equal then program compare both string character by character and return if both string is equal or not according to the string analysis. Below is both method for comparing a string using library function or without using library functions.
Using Library Function
strcmp(string1 ,string2)
Without Using Library Function
for(i=0,j=0;str1[i]!='\0',str2[j]!='\0';i++,j++)
{
if(str1[i]==str2[j])
{
flag=1;
}
else
{
flag=0;
}
}
This is a condition is used when the size of both strings is equal and we have to compare both the string character by character.
Sponsor: Install and access your important work applications and software no matter where you from any device ( PC / Android / iOS ) with a cloud desktop from www.CloudDesktopOnline.com. For cloud-related business software such as SharePoint, Office365, try Apps4Rent.
Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post or if you have any Query you can ask there with lots of coders also suggest to your Friends to join and like our page.
Try Yourself - C++ Program To Check String Is Palindrome Or Not
Solution:-
#include<bits/stdc++.h>
using namespace std;
int main()
{
/*Visit - www.programmingwithbasics.com*/
cout<<"=====================================";
cout<<"\nVisit - www.programmingwithbasics.com";
cout<<"\n=====================================";
char str1[20],str2[20],i=0,j=0,flag=0;
cout<<"\n\nEnter First String : \n";
gets(str1);
cout<<"Enter Second String : \n";
gets(str2);
while(str1[i]!='\0')
{
i++;
}
while(str2[j]!='\0')
{
j++;
}
if(i!=j)
{
flag=0;
}
else
{
for(i=0,j=0;str1[i]!='\0',str2[j]!='\0';i++,j++)
{
if(str1[i]==str2[j])
{
flag=1;
}
else
{
flag=0;
}
else
{
flag=0;
}
}
}
if(flag==0)
{
cout<<"Both Strings Are Not Equal\n";
}
else
{
cout<<"Both Strings Are Equal\n";
}
return 0;
}
Output:-
You May Also See
1. C Program To Find Character Is Vowel Or Not
2. C Program To Calculate Factorial Of A Given Number
3. C Program To Read Integer (N) And Print First Three Powers (N^1, N^2, N^3)
4. C++ Program To Check Number Is Even Or Odd Using If/Else Statements
5. C++ Program To Check Number Is Prime Or Not Using If/Else Statements
6. C++ Program To Check Character Is Uppercase, Lowercase Alphabet Or A Digit Or A Special Symbol Using If/Else Statements
7. C++ Program To Find Quotient And Reminder Of Two Numbers Using If/Else Statements
8. Java Program To Check Character Is Uppercase, Lowercase Alphabet Or A Digit Or A Special Symbol
9. Java Program To Find Greatest Among Three Numbers
10. Java Program For Find The Salary Of An Employee With Employee Grade
for(i=0,j=0;str1[i]!='\0',str2[j]!='\0';i++,j++)
ReplyDelete{
if(str1[i]==str2[j])
flag=1;
else
flag=0 //There should be a else part...otherwise it fails to compare between hello &
//helli
}
Thank you Very Much Nick Moni for notifying Errors. Now Program Is Updated
DeleteKeep Sharing and Keep visiting
For instance :
ReplyDeleteAbcde
abcde
-> 1 ( following your code )
In fact, it was 0.