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

Answer Posted / dinesh

#include<stdio.h>
#include<conio.h>
void main()
{
char name1[20],name[20];
int i,j,c=0;
clrscr();
printf("enter two strings");
scanf("%s%s",name1,name);
for(i=0,j=0;name1[i]!='\0'||name[j]!='\0';i++,j++)
{
if(name1[i]!=name[j])
{
c++;
}
}
if(c==0)
printf("equal strings");
else
printf("not equal strings");
}

Is This Answer Correct ?    10 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a constant and types of constants in c?

604


What does void main return?

606


Differentiate between declaring a variable and defining a variable?

609


What is difference between structure and union in c?

548


What is the basic structure of c?

557






Explain how do you convert strings to numbers in c?

596


Why clrscr is used after variable declaration?

1041


What are the advantages and disadvantages of c language?

562


What is the difference between void main and main in c?

626


What are the three constants used in c?

547


What is #include stdlib h?

616


What is the difference between declaring a variable and defining a variable?

724


What is nested structure?

575


What is a ternary operator in c?

654


What is structure in c definition?

576