Learn C ProgrammingLearn ProgrammingPrograms On StringsResources

091. Write a program to compare two strings in C language

By September 18, 2012 September 5th, 2018 No Comments
#include<stdio.h>
#include<conio.h>  
#include<process.h>
main()
{
	int i;
	char *s1,*s2;
	clrscr();
	printf("Enter the string 1....");
	scanf("%s",s1);
	printf("Enter the string 2....");
	scanf("%s",s2);

	for(i=0;s1[i]!='\0';i++)
	{
		 if(s1[i]!=s2[i])
			{
				if(s1[i]>s2[i])
					printf("\nString 1 is greater...");
				else
					printf("\nString 2 is greater...");
				getch();
				exit(0);
			}
	}
	printf("String are equal....");
	getch();
}


Leave a Reply

DEMO01