Write a program to compare two strings without using the
strcmp() function

Answer Posted / sujith

I have been seeing lot of answers posted on top of mine.
here is another highly optimized version.

int str_cmp (const char *s1, const char *s2)
{
while (*s1 == *s2++)
if (*s1++ == 0)
return (0);
return (*(unsigned char *)s1 - *(unsigned char *)--s2);
}
before marking it as not an answer, I urge you to try it once!
Trust me, it works.

Is This Answer Correct ?    6 Yes 15 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the use of gets and puts?

590


What does == mean in texting?

653


Explain can the sizeof operator be used to tell the size of an array passed to a function?

586


What is the difference between constant pointer and constant variable?

740


Explain what header files do I need in order to define the standard library functions I use?

642






Explain 'bus error'?

547


a linearly ordered set of data elements that have the same structure and whose order is preserved in storage by using sequential allocation a) circular b) ordinary c) array d) linear list

627


What does double pointer mean in c?

568


Compare interpreters and compilers.

633


What is a shell structure examples?

583


"C" language developed by "Dennis Ritchie" at AT & T. his remarks are a) too general, too abstract b) could deal with only specific problems c) lost generality of BCPL and B restored d) no remarks

650


What are the different types of C instructions?

664


Can we replace the struct function in tree syntax with a union?

769


What is the right type to use for boolean values in c?

576


Is linux written in c?

594