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 value of c?
How can I remove the trailing spaces from a string?
Why cant I open a file by its explicit path?
What is pragma in c?
What is difference between far and near pointers?
1. Write a function to display the sum of two numbers in the following ways: By using (i) pass by value (ii) pass by address a. function with argument and with return value b. function with argument and without return value c. without argument , with return value d. without argument , without return value Note: Use pass by address.
How does struct work in c?
What do you mean by dynamic memory allocation in c?
What is context in c?
disply the following menu 1.Disply 2.Copy 3.Append; as per the menu do the file operations 4.Exit
What are # preprocessor operator in c?
What 'lex' does?
What is meant by operator precedence?
Which driver is a pure java driver
typedef enum { html, java, javascript, perl, cgi } lang;The above statement defines a : a) Union b) User defined type c) Enumerated variable d) none