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

How do you declare a set in c++?

771


What is the most powerful coding language?

852


When do we run a shell in the unix system?

854


Why struct is used in c++?

852


What is abstract keyword in c++?

863


Will the following program execute?

817


What is the correct syntax for inheritance a) class aclass : public superclass b) class aclass inherit superclass c) class aclass <-superclass

958


What is object file? How can you access object file?

878


What do you mean by public protected and private in c++?

820


What is the difference between an external iterator and an internal iterator? Describe an advantage of the external iterator.

830


Why is the function main() special?

877


Are there any special rules about inlining?

824


Do inline functions improve performance?

863


Is c++ primer good for beginners?

825


What are virtual functions in c++?

930