Implement strcmp

Answers were Sorted based on User's Feedback



Implement strcmp..

Answer / 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

Implement strcmp..

Answer / shanmugavalli

int strcmp(const char *src, const char *dest)
{

while (*src && *dest && (*src==*dest))
{
src++;
dest++;
}
return (*src-*dest);

}

Is This Answer Correct ?    1 Yes 1 No

Implement strcmp..

Answer / sanjith

#inclde<string.h>
int d;
class test
public: void read()
void cmb()
};
void test::read()
{ cout<<"Enter the first string:";
cin>>s1;
cout<<"Enter the second string";
cin>>s2;
}
void test::cmb()
{
d=strcmp(s1,s2);
}
main()
{
test t1,t2;
t1.read();
t2.cmb();
t2.print();
}

Is This Answer Correct ?    1 Yes 4 No

Post New Answer

More C++ General Interview Questions

Why c++ is not a pure oop language?

0 Answers  


if int1 has the value 12, int has the value 18, and int3 has the value 21, what is the result: int1 < int2 && int2 < int 3

3 Answers  


a class that maintains a pointer to an object that is programatically accessible through the public interface is known as?

2 Answers   CTS,


Does c++ vector allocate memory?

0 Answers  


Why do we use iterators?

0 Answers  






What is the use of register keyword with the variables?

0 Answers  


Why struct is used in c++?

0 Answers  


What is set in c++?

0 Answers  


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

0 Answers  


"How will you merge these two arrays? Write the program Array: A 1 18 22 43 Array: B 3 4 6 20 34 46 55 Output Array: C 1 3 4 6 18 20 22 34 43 46 55"

9 Answers   College School Exams Tests, HCL,


Explain "passing by value", "passing by pointer" and "passing by reference" ?

5 Answers  


What is general form of pure virtual function? Explain?

0 Answers  


Categories