Implement strcmp
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
Types of storage and scope of each type
What is stream and its types in c++?
Which one is a preferred language C or C++? Why?
Who was the creator of c++?
Which sort is best for the set: 1 2 3 5 4 a) Quick Sort b) Bubble Sort c) Merge Sort
Differentiate between declaration and definition in C++?
What is the iunknown interface?
What do the keywords volatile and mean mutable?
How do we balance an AVL Tree in C++?
Can we use clrscr in c++?
What is the difference between ++ count and count ++?
What is basic if statement syntax?