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 ?    10 Yes 13 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the data types present in c?

617


Write a program to print ASCII code for a given digit.

677


What is LINKED LIST? How can you access the last element in a linked list?

625


What are the Advantages of using macro

675


What is switch in c?

636






A variable that is defined in a specified portion of a program but can be used throughout the program a) global variable b) local variable c) character d) none

719


What is a spanning Tree?

940


Should a function contain a return statement if it does not return a value?

588


What 'lex' does?

710


Write a program in "C" to calculate the root of a quadratic equation ax^2+bx+c=0, where the value of a,b & c are known.

1716


For what purpose null pointer used?

600


What is an lvalue?

627


What is the size of array float a(10)?

647


What is difference between arrays and pointers?

573


write a program to copy the string using switch case?

2391