Implement strcmp

Answer Posted / lylez00

#include <string.h>
/* strcmp */
int (strcmp)(const char *s1, const char *s2)
{
unsigned char uc1, uc2;
/* Move s1 and s2 to the first differing characters
in each string, or the ends of the strings if they
are identical. */
while (*s1 != '\0' && *s1 == *s2) {
s1++;
s2++;
}
/* Compare the characters as unsigned char and
return the difference. */
uc1 = (*(unsigned char *) s1);
uc2 = (*(unsigned char *) s2);
return ((uc1 < uc2) ? -1 : (uc1 > uc2));
}

Is This Answer Correct ?    7 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is meaning of in c++?

660


Explain data encapsulation?

595


Differentiate between the message and method in c++?

594


In c++, what is the difference between method overloading and method overriding?

574


What is type of 'this' pointer?

586






What is a constant reference?

603


What is the difference between object-oriented programming and procedural programming?

679


Explain about vectors in c ++?

582


Specify some guidelines that should be followed while overloading operators?

605


What is the use of endl in c++?

579


What is the difference between #import and #include in c++?

580


Explain what you mean by a pointer.

611


What is the type of 'this' pointer?

583


How would you use the functions randomize() and random()?

614


Write a program to add three numbers in C++ utilizing classes.

608