|
Get 9,000+ Interview Questions with Answers in an eBook
C Source Codes List | Source Code Home
Program : Program to compare two input strings.
/* Prg. to compare two input strings */
#include
#include
#include
#include
char s1[80],s2[80];
int a,b;
int strcmp(char *s,char *t);
void main()
{
int c;
clrscr();
printf("\t\t\tWELCOME TO THE PROGRAM SIR/MADAM\n\n\n");
printf("Enter string 1 :- ");
gets(s1);
printf("Enter string 2 :- ");
gets(s2);
c=strcmp(s1,s2);
if (c==0)
printf("Strings are similar.");
else if (a>b)
{
printf("Strings are not similar.");
printf("\nFirst string is lenthier than the second string.");
}
else if (b>a)
{
printf("Strings are not similar.");
printf("\nFirst string is shorter than the second string.");
}
else
printf("\nStrings are not similar though they are equal in length.");
printf("\n\n\n\n\n\t\t\tHAVE A NICE DAY! BYE.");
getch();
}
int strcmp(char s[],char t[])
{
int i;
a=strlen(s1);
b=strlen(s2);
if (a>b)
{
for(i=0;*s!='\0';i++)
{
if (*s==*t)
{
*s=*(s+i);
*t=*(t+i);
}
else
return(*s - *t);
}
return(0);
}
else
{
for(i=0;*t!='\0';i++)
{
if (*s==*t)
{
*s=*(s+i);
*t=*(t+i);
}
else
return(*s - *t);
}
return(0);
}
}
C Source Codes List | Source Code Home
|
|
|