Enter string and compare them both are same or not

Write a program to enter two user define string and compare them both are same or not.


Source Code:

#include<stdio.h>
#include<conio.h>
void main()
{
	char a[10],b[10];
	int i,len_1=0,len_2=0,count=0;
	clrscr();
	printf("Enter the First String:");
	gets(a);
	for(i=0;a[i]!=NULL;i++)
	{
		len_1++;
	}
	printf("Enter the Second String:");
	gets(b);
	for(i=0;b[i]!=NULL;i++)
	{
		len_2++;
	}
	if(len_1==len_2)
	{
		for(i=0;i<len_1;i++)
		{
			if(a[i]==b[i])
			{
				count++;
			}

		}
		if(count==len_1)
		{
			printf("Both strings are same");
		}
		else
		{
			printf("Both strings are not same");
		}
	}
	else
	{
		printf("Both strings are not same:");
	}
	getch();
}

Output:

Enter the First String: Bhavesh
Enter the Second String: Jain

Both strings are not same
Enter the First String: Bhavesh
Enter the Second String: Bhavesh

Both strings are same

Leave a Reply

Your email address will not be published. Required fields are marked *