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
The difference between printf and fprintf is ?
What language is windows 1.0 written?
write a progrmm in c language take user interface generate table using for loop?
If I have a char * variable pointing to the name of a function ..
What type of function is main ()?
What is multidimensional arrays
write a c program to find the largest and 2nd largest numbers from the given n numbers without using arrays
What are compound statements?
What is array of structure in c programming?
How can I read/write structures from/to data files?
What are the parts of c program?
Explain how can I prevent another program from modifying part of a file that I am modifying?
What is the general form of function in c?
if p is a string contained in a string?
Tell me the use of bit field in c language?