PROGRAM TO COMPARE TWO STRINGS WITHOUT USING STRING FUNCTION

/*PROGRAM TO COMPARE TWO STRINGS WITHOUT USING STRING FUNCTION*/
#include<stdio.h>
#include<conio.h>
void main()
{
char a[10],b[10];
int i,count=0,count1=0,m;
clrscr();
printf(“Enter first string: “);
gets(a);
printf(“Enter second string: “);
gets(b);
i=0;
while(a[i]!=’\0′)
{
count++;
i++;
}
i=0;
while(b[i]!=’\0′)
{
count1++;
i++;
}
if(count==count1)
{
i=0;
m=0;
while(a[i]!=’\0′)
{
if(a[i]==b[i])
m++;
i++;
}
if(m==count)
printf(“Strings are equal”);
else
printf(“strings are not equal”);
}
else if(count>count1)
printf(“%s is larger than %s”,a,b);
else
printf(“%s is larger than %s”,b,a);
getch();
}

Leave a Reply

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