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


Please Help Members By Posting Answers For Below Questions

What is the purpose of 'register' keyword in c language?

630


Are the variables argc and argv are local to main?

790


Explain what are linked list?

627


Give differences between - new and malloc() , delete and free() ?

613


What is union and structure?

575






What is this pointer in c plus plus?

599


By using C language input a date into it and if it is right?

575


What is the use of c language in real life?

531


How can I make sure that my program is the only one accessing a file?

681


What are two dimensional arrays alternatively called as?

662


What is the advantage of an array over individual variables?

745


When should the volatile modifier be used?

688


What is sizeof in c?

572


What is difference between array and structure in c?

582


If you know then define #pragma?

677