Monday, June 25, 2018

Program to compare two given strings - DS (C Program)

#include<stdio.h>
void main()
{
char *s1;
char *s2;
int i,t=0,len1=0,len2=0;
clrscr();
printf("Enter the First String : ");
gets(s1);
printf("Enter the Second String : ");
gets(s2);
for(i=0;*(s1+i)!=NULL;i++,len1++);
for(i=0;*(s2+i)!=NULL;i++,len2++);
if(len1==len2)
{
for(i=0;*(s1+i)!=NULL;i++)
{
if(*(s1+i)!=*(s2+i))
{
t=1;
break;
}
}
if(t==1)
{
printf("\nString does not match...");
}
else
{
printf("\nString Matched...");
}
}
else
{
printf("\nString does not match...");
}
getch();
}

No comments:

Post a Comment