C Program to Compare Two Strings Using Pointers. C program compares two strings without using a library function or string compares in c without using a library function. we are comparing two strings using pointers for comparing two strings we are not using an strcmp function we are comparing with the help of a pointer.
Explanation: In this problem, First take input from the user first take a first string and take a second string and assign both strings in two pointer type variables separately, after that run a while loop and put the condition that string1 and string2 are the same and also both strings are not equal null till increase both string by one character and repeat the process again and again. If the first string is the same as a second string then print the message "Both Strings Are Same" if not then print "Both Strings Is Not Same" on the screen.
Recommended: If this post is beneficial for you and you want Updates for New posts then please like our Facebook Page or Facebook Group. If you have any queries you can ask them there with lots of coders also suggest your Friends join and like our page, so we can help our community, and don't forget to Subscribe. Enter your Email and click to subscribe.
Recommended: If this post is beneficial for you and you want Updates for New posts then please like our Facebook Page or Facebook Group. If you have any queries you can ask them there with lots of coders also suggest your Friends join and like our page, so we can help our community, and don't forget to Subscribe. Enter your Email and click to subscribe.
C Program to Compare Two Strings Using Pointers
#include <iostream>
using namespace std;
int main()
{
char string1[50],string2[50],*str1,*str2;
int i,equal = 0;
printf("Enter The First String: ");
scanf("%s",string1);
printf("Enter The Second String: ");
scanf("%s",string2);
str1 = string1;
str2 = string2;
while(*str1 == *str2)
{
if ( *str1 == '\0' || *str2 == '\0' )
break;
str1++;
str2++;
}
if( *str1 == '\0' && *str2 == '\0' )
printf("\n\nBoth Strings Are Equal.");
else
printf("\n\nBoth Strings Are Not Equal.");
}
Output Compare Two Strings Using Pointers in C
Related to Pointer
- C Program for Reverse a String Using Pointer
- Open a File(open a Program Itself) Using Pointer
- C++ Program To Check An Array Is Armstrong Or Not
- C++ Program To Sort An Array Using BUBBLE SORT TECHNIQUE
- C++ Program To Sort An Array Using SELECTION SORT TECHNIQUE
- C++ Program To Find Cube Of Any Number Using Functions
- C++ Program To Perform All Arithmetic Operations Using Functions
0 Comments: