#include<stdio.h>
#include<conio.h>
int strcmp(char [],char []);
void main()
{
int i;
char a[80],b[80];
clrscr();
printf("Enter 1st string\n");
gets(a);
printf("Enter string to compare\n");
fflush(stdin);
gets(b);
i=strcmp(a,b);
printf("%d",i);
if(i==0)
printf("Strings are same\n");
else
printf("\nNot same");
getch();
}
int strcmp(char x[],char y[])
{
int j;
for(j=0;x[j]&&y[j];j++)
{
if(x[j]!=y[j])
return(x[j]-y[j]);
}
return(0);
}
#include<conio.h>
int strcmp(char [],char []);
void main()
{
int i;
char a[80],b[80];
clrscr();
printf("Enter 1st string\n");
gets(a);
printf("Enter string to compare\n");
fflush(stdin);
gets(b);
i=strcmp(a,b);
printf("%d",i);
if(i==0)
printf("Strings are same\n");
else
printf("\nNot same");
getch();
}
int strcmp(char x[],char y[])
{
int j;
for(j=0;x[j]&&y[j];j++)
{
if(x[j]!=y[j])
return(x[j]-y[j]);
}
return(0);
}
More c programs at : http://goo.gl/0Mb75Y
ReplyDelete