#include<stdio.h>
int string_comparision(char s1[],char s2[],int l,int m)
{
int i,j;
for(i=0,j=0; i<=l||j<=m; i++,j++)
{
if(s1[i]<s2[j])
{
return -1;
}
else if(s1[i]>s2[j])
{
return 1;
}
else if(s1[i]==s2[j])
{
continue;
}
}
i--,j--;
if(i==l || j==m)
{
return 0;
}
}
int string_length(char string[] )
{
int p=0;
while(string[p]!='\0')
{
p++;
} return p;
}
void main()
{
char s1[50],s2[50];
int q,r,z,k;
printf("enter string 1");
gets(s1);
q=string_length(s1);
printf("enter string 2");
gets(s2);
r=string_length(s2);
z=string_comparision(s1,s2,q,r);
if(z== 1)
{
printf("string 1 is greater than string 2");
}else if(z == -1)
{
printf("string 1 is less than string 2");
}else
{
printf("Both Strings are Equal");
}
}
Note: Need to be arranged in compiler after copied
OutPut:
enter string 1
hElloworld
enter string 2
helloworld
string 1 is less than string 2