write a own function to compare two strings with out using
stringcomparition function?
Answer Posted / ravikiran p sattigeri
/* str_cmp : Comapares the character strings s1 and s2, and
returns negative, zero or positive if s1 is
lexicographically less than, equal to, or greater than s2.
The value is obtained by subtracting the characters at the
first position where s1 and s2 disagree */
/* return < 0 if s1<s2, 0 if s1==s2, >0 if s1>s2 */
int str_cmp (char *s1, char *s2)
{
while(*s1++ == *s2++) {
if (*s1 == '\0')
return 0;
}
return *S1 - *s2;
}
Is This Answer Correct ? | 13 Yes | 3 No |
Post New Answer View All Answers
What is the purpose of 'register' keyword in c language?
Are the variables argc and argv are local to main?
Explain what are linked list?
Give differences between - new and malloc() , delete and free() ?
What is union and structure?
What is this pointer in c plus plus?
By using C language input a date into it and if it is right?
What is the use of c language in real life?
How can I make sure that my program is the only one accessing a file?
What are two dimensional arrays alternatively called as?
What is the advantage of an array over individual variables?
When should the volatile modifier be used?
What is sizeof in c?
What is difference between array and structure in c?
If you know then define #pragma?