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
p*=(++q)++*--p when p=q=1 while(q<=6)
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
Why main is not a keyword in c?
What is FIFO?
What is d'n in c?
What is the stack in c?
Can the “if” function be used in comparing strings?
What is variable declaration and definition in c?
process by which one bit patten in to another by bit wise operation is? (a) masking, (b) pruning, (c) biting, (d) chopping,
What do you mean by dynamic memory allocation in c? What functions are used?
What does. int *x[](); means ?
How many data structures are there in c?
What are predefined functions in c?
What is the newline escape sequence?
What is the difference between array and pointer?