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
What is the size of structure pointer in c?
How can you find out how much memory is available?
What is realloc in c?
what is the c source code for the below output? 5555555555 4444 4444 333 333 22 22 1 1 22 22 333 333 4444 4444 5555555555
What is const volatile variable in c?
What is non linear data structure in c?
What is strcpy() function?
What are the types of operators in c?
Explain the difference between ++u and u++?
Can you please explain the scope of static variables?
What are the 4 types of functions?
What are the advantages of using linked list for tree construction?
What is the difference between if else and switchstatement
You are to write your own versions of strcpy() and strlen (). Call them mystrcpy() and mystrlen(). Write them first as code within main(), not as functions, then, convert them to functions. You will pass two arrays to the function in the case of mystrcpy(), the source and target array.
Why do we need volatile in c?