Write a program to compare two strings without using the
strcmp() function

Answer Posted / sujith

#include<stdio.h>
int str_cmp(const char *s1, const char *s2)
{
unsigned int i = 0, diff;
while(*(s1+i) && *(s2+i))
{
diff = (*(s1+i)-*(s2+i));
if(!diff)i++;
else break;
}
return diff;
}
int main()
{
printf("chuma %d ", str_cmp("abcd","abcde"));
return 0;
}
U can use this as a prototype and enhance this. I havent
even tried compilng this.
Sujith

Is This Answer Correct ?    115 Yes 113 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can I do peek and poke in c?

599


Why can’t constant values be used to define an array’s initial size?

818


what are the advanced features of functions a) function declaration and prototypes b) calling functions by value or by reference c) recursion d) all the above

650


What is clrscr ()?

624


if the area was hit by a virus and so the decrease in the population because of death was x/3 and the migration from other places increased a population by 2x then annually it had so many ppl. find our the population in the starting.

4480






What is meant by 'bit masking'?

868


What is the use of ?: Operator?

653


What is header file definition?

556


Where in memory are my variables stored?

613


Explain what are run-time errors?

595


Tell me when would you use a pointer to a function?

586


Explain about C function prototype?

593


What is the basic structure of c?

547


int far *near * p; means

3106


What is type qualifiers?

643