Hey,
How is the strcmp(char*, char*) implemented?
I need to implement it myself for my Comp Science class, and this is what I got:
But it looks too long and clumsy for such a simple function.PHP Code:int strcmp(const char* s1, const char* s2)
{
const char* p1 = s1 - 1;
const char* p2 = s2 - 1;
while (*++p2 == *++p1)
if (!*p2 || !*p1)
break;
if (*p2 > *p1)
return (-1);
else if (*p1 > *p2)
return (1);
return (0);
}
Thanks.




Reply With Quote