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
What are called c variables?
Who invented b language?
Can we increase size of array in c?
Program will then find the largest of three numbers using nested if-else statements. User is prompted to enter three numbers. Program will find the largest number and display it on the screen. All three numbers entered by the user are also displayed. If user enters 21, 33, and 5, the output should be as follows: You entered: 21, 33 and 5. The largest number is 33.
What is the purpose of the following code? Is there any problem with the code? void send(int count, short *to, short *from) { /* count > 0 assumed */ register n = (count + 7) / 8; switch (count % 8) { case 0: do { *to = *from++; case 7: *to = *from++; case 6: *to = *from++; case 5: *to = *from++; case 4: *to = *from++; case 3: *to = *from++; case 2: *to = *from++; case 1: *to = *from++; } while (--n > 0); } }
How many keywords are there in c?
Explain what is the difference between #include and #include 'file' ?
Differentiate between Macro and ordinary definition.
Explain how do you list a file’s date and time?
Which header file should you include if you are to develop a function which can accept variable number of arguments?
What are categories used for in c?
What are the types of i/o functions?
What is difference between array and pointer in c?
What are the keywords in c?
What are the basic data types associated with c?