Implement the strcmp function as efficiently as you can.. How do you handle errors if you had to
int strcmp (const char *s1, const char *s2) { int c1, c2; do { /* Use "unsigned char" to make the implementation 8-bit clean */ c1 = *((unsigned char *)(s1++)); c2 = *((unsigned char *)(s2++)); if (c1 != c2) { return (c1 - c2); } } while (c1 != 0); return 0; }
Implement the strcmp function
int
strcmp (const char *s1, const char *s2)
{
int c1, c2;
do
{
/* Use "unsigned char" to make the implementation 8-bit clean */
c1 = *((unsigned char *)(s1++));
c2 = *((unsigned char *)(s2++));
if (c1 != c2)
{
return (c1 - c2);
}
}
while (c1 != 0);
return 0;
}