5 using c language please explain Write a function to compar
5. using c language, please explain
Write a function to compare two strings for equality. If they are equal, zero is returned, otherwise the difference in value between the first two non-matching characters.Solution
#include<stdio.h>
int main() {
char str1[30], str2[30];
int i;
boolean flag=false;
printf(\"\ Enter two strings :\");
gets(str1);
gets(str2);
i = 0;
while (str1[i] == str2[i] && str1[i] != \'\\0\')
{
i++;
if (str1[i] == str2[i])
flag=true;
}
if(flag==true)
return 0;
else
{
if (str1[i] > str2[i])
int diff=str1[0]-str2[0];
else
int diff=str2[0]-str1[0];
return diff;
}
}
