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

Answer Posted / belsia

void main()
{
char a[10],b[10];
int i=0;
scanf("%s%s",a,b);
if(strlen(a)!=strlen(b))
printf("they are different strings");
else
{
while(a[i]!='\0')
{
if(a[i]==b[i])
i++;
else
{
printf("They are different strings");
exit(0);
}
printf("Both are same");
}
getch();
}

Is This Answer Correct ?    27 Yes 16 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is it better to use malloc() or calloc()?

649


What is meant by errors and debugging?

649


.main() { char *p = "hello world!"; p[0] = 'H'; printf("%s",p); }

712


program for reversing a selected line word by word when multiple lines are given without using strrev

1947


How can I trap or ignore keyboard interrupts like control-c?

620






What is the importance of c in your views?

597


Tell me with an example the self-referential structure?

566


What is the scope of static variable in c?

537


Is c++ based on c?

656


Explain can the sizeof operator be used to tell the size of an array passed to a function?

597


What are the rules for identifiers in c?

588


What library is sizeof in c?

574


Why use int main instead of void main?

599


any "C" function by default returns an a) int value b) float value c) char value d) a & b

667


What is meant by preprocessor in c?

536