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
how to construct a simulator keeping the logical boolean gates in c
What is the use of a ‘ ’ character?
Compare interpreters and compilers.
hi, which software companys will take,if d candidate's % is jst 55%?
Write a C Program That Will Count The Number Of Even And Odd Integers In A Set using while loop
Explain that why C is procedural?
What is bubble sort in c?
Explain what is output redirection?
main() { struct s1 { char *str; struct s1 *ptr; }; static struct s1 arr[] = { {"Hyderabad",arr+1}, {"Bangalore",arr+2}, {"Delhi",arr} }; struct s1 *p[3]; int i; < BR> for(i=0;i<=2;i++) p[i] = arr[i].ptr; printf("%s ",(*p)->str); printf("%s ",(++*p)->str); printf("%s ",((*p)++)->str); }
What is the size of empty structure in c?
Why do we need arrays in c?
Do variables need to be initialized?
Write a program to generate the Fibinocci Series
What is pragma c?
What is header file in c?