In below program we are comparing two string with the help of pointers, without using strcmp() function. A user defined function str_cmp() is created which takes two character pointers as argument. If this function returns 1 than the strings are equal and unequal if returns 0. Just take a look on the program, if you are facing any problem to understand then feel free to ask by commenting below.
Also Read: C++ Program to reverse a string
Also Read: C++ Program to Count no. of words in a string
#include<iostream>
#include<stdio.h>
using namespace std;
main()
{
char str1[50],str2[50];
int str_cmp(char*,char*);
cout<<“Enter first string:”;
gets(str1);
cout<<“Enter second string:”;
gets(str2);
if(str_cmp(str1,str2))
cout<<“nStrings are equal”;
else
cout<<“nStrings are not equal”;
return 0;
}
int str_cmp(char *s1,char *s2)
{
while(*s1==*s2)
{
if(*s1==’