You are on page 1of 1

#include<iostream.

h>
#include<conio.h>
int strcomparison(char str1[20],char str2[20])
{
int i,n=0,m=0,flg=0;
while(str1[n]!='\0')
{
n++;
}
while(str2[m]!='\0')
{
m++;
}
if(n!=m)
{
flg=-1;
}
else
{
for(i=0;i<n;i++)
{
if(str1[i]!=str2[i])
{
flg=1;
}
}
}
return(flg);
}
void main()
{
int f;
char str1[20],str2[20];
clrscr();
cout<<"Enter first string\n";
cin.getline(str1,20);
cout<<"Enter second string\n";
cin.getline(str2,20);
f=strcomparison(str1,str2);
if(f==-1)
{
cout<<"Size of the string is not same\n";
}
else if(f==0)
{
cout<<"Both the strings are same\n";
}
else
{
cout<<"Characters of the strings are not same\n";
}
getch();
}

You might also like