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
Is fortran still used in 2018?
What is a void pointer? When is a void pointer used?
Explain what is page thrashing?
Ow can I insert or delete a line (or record) in the middle of a file?
Discuss the function of conditional operator, size of operator and comma operator with examples.
What is the use of in c?
What is the difference between union and structure in c?
c programs are converted into machine language with the help of a) an interpreter b) a compiler c) an operatinf system d) none of the above
Explain with the aid of an example why arrays of structures don’t provide an efficient representation when it comes to adding and deleting records internal to the array.
Is it possible to use curly brackets ({}) to enclose single line code in c program?
Why is c not oop?
A function can make the value of a variable available to another by a) declaring the variable as global variable b) Passing the variable as a parameter to the second function c) Either of the two methods in (A) and (B) d) binary stream
what is the difference between north western polytechnique university and your applied colleges?? please give ur answers for this. :)
When can you use a pointer with a function?
How can I remove the leading spaces from a string?