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
What is the incorrect operator form following list(== , <> , >= , <=) and what is the reason for the answer?
Is c procedural or object oriented?
What is use of integral promotions in c?
Why we use stdio h in c?
What is the difference between c &c++?
c language interview questions & answer
What is the total generic pointer type?
please send me the code for multiplying sparse matrix using c
What happens if header file is included twice?
a program that can input number of records and can view it again the record
What is omp_num_threads?
What is openmp in c?
What is malloc return c?
How to find a missed value, if you want to store 100 values in a 99 sized array?
What is the use of header?