Write a program to compare two strings without using the
strcmp() function

Answer Posted / aiattack

#include <stdio.h>
#include <string.h>
int main()
{
char a[10];
char b[10];
int check = 0;
gets(a);
gets(b);
if (strlen(a)!=strlen(b)) {
printf("Strings don't match!");
} else {
for(int i=0, j=0; a[i] != '' || b[i] != ''; i++, j++) {
if(a[i] == b[i]) {
check = 0;
} else {
check ++;
break;
}
}
if (check == 0) printf("Strings match!");
else printf("Strings don't match");
}
return 0;
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the use of pragma in embedded c?

588


Differentiate between full, complete & perfect binary trees.

669


What is an arrays?

650


Explain how do I determine whether a character is numeric, alphabetic, and so on?

648


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); } }

1953






What is strcpy() function?

652


‎How to define structures? · ‎

622


Explain how can type-insensitive macros be created?

570


How will you delete a node in DLL?

677


What is difference between structure and union?

593


What is the difference between array and linked list in c?

596


What's the right way to use errno?

619


write a C program: To recognize date of any format even formats like "feb-02-2003","02-february-2003",mm/dd/yy, dd/mm/yy and display it as mm/dd/yy.

3332


What is spaghetti programming?

668


If the size of int data type is two bytes, what is the range of signed int data type?

583