I know there is a function for comparing string but i am making it to just improve my concepts.
error : 2 is coming as answer when i put same sting in both place.
Code:
#include<stdio.h>
main()
{
char str1[] = "hello" ;
char str2[]= "hello" ;
int q;
q = xstrcmp(str1,str2);
printf("%d",q);
}
int xstrcmp(char *s1,char *s2)
{
while( *s1 != '\0' || s2 != '\0')
{
if (*s1 != *s2)
{
break;
}
s1= s1+1;
s2=s2+1;
}
if ( *s1 == '\0' && *s2 == '\0')
return(0);
else if(*s1 == '\0' && *s2 != '\0')
return(1);
else if(*s1 != '\0' && *s2 == '\0')
return(2);
else if(*s1 != *s2)
return(3);
}