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

When can you use a pointer with a function?

578


the portion of a computer program within which the definition of the variable remains unchanged a) mode b) module c) scope d) none

656


Explain what are binary trees?

618


What is the use of ?: Operator?

673


Why doesnt long int work?

619






What is the purpose of sprintf() function?

613


Write a program to display all the prime nos from 1 to 1000000, your code should not take time more than a minute to display all the nos.

1607


Write the syntax and purpose of a switch statement in C.

635


Explain how are portions of a program disabled in demo versions?

665


What is the purpose of realloc()?

682


What is enumerated data type in c?

637


What are the 4 types of programming language?

599


What is the value of c?

585


Tell us something about keyword 'auto'.

674


Why is not a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it is been freed?

612