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

Define whitespace in C++.

968


What is the difference between structure and class?

820


What does int * mean in c++?

967


Is map sorted c++?

751


What is format for defining a structure?

827


Explain the different access specifiers for the class member in c++.

754


Tell me what are static member functions?

818


What is the standard template library (stl)?

1073


What is abstraction with real time example?

893


How do you define/declare constants in c++?

790


What does the linker do?

799


What is split a string in c++?

929


What is abstract class in c++?

800


Mention the purpose of istream class?

836


Can constructor be static in c++?

865