Write a program to compare two strings without using the
strcmp() function
Answer Posted / sandeep a
// Optimize the above soln...
#include<stdio.h>
int str_cmp(const char *s1, const char *s2)
{
unsigned int i = 0, diff;
while(s1[i]!= '\0' || s2[i] != '\0'){
diff = s1[i] - s2[i];
if(!diff)i++;
else break;
}
return diff;
}
int main(int argc, char *argv[1])
{
printf("chuma %d ", str_cmp("abcd","abcde"));
return 0;
}
| Is This Answer Correct ? | 35 Yes | 49 No |
Post New Answer View All Answers
How can type-insensitive macros be created?
An instruction which is analysed and acted upon by the processor prior to the compiler going its work a) directive b) constructive c) constant d) absolute mode
Can a function argument have default value?
What will be the outcome of the following conditional statement if the value of variable s is 10?
How many loops are there in c?
Explain why can’t constant values be used to define an array’s initial size?
What are enums in c?
What is d scanf?
which of the following is not a character constant a) 'thank you' b) 'enter values of p, n ,r' c) '23.56E-o3' d) all of the above
Why flag is used in c?
What is %lu in c?
How do c compilers work?
Why do we use int main?
void main(){ int a; a=1; while(a-->=1) while(a-->=0); printf("%d",a); }
What does double pointer mean in c?