#include<stdio.h>
int string_comparision(char *s1,char *s2)
{
while(*s1!='\0'&&*s2!='\0')
{
if(*s1==*s2)
{
s1++;
s2++;
}
else if(*s1>*s2)
{
return 1;
} else if(*s1<*s2)
{
return -1;
}
}
return 0;
}
void main()
{ char s1[50],s2[50];
int q,r,z,k;
printf("enter string 1");
gets(s1);
printf("enter string 2");
gets(s2);
z=string_comparision(s1,s2);
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 1hello
enter string 2hellO
string 1 is greater than string 2