Replicate the standard string library function strcmp().

#include <stdio.h>

int fnstrcmp(char *, char *);

int main(void)
{
char name1[40], name2[40];
int val;
clrscr();
printf("\nEnter a name : ");
gets(name1);
printf("\nEnter another name : ");
gets(name2);

val = fnstrcmp(name1, name2);

if(val == 0)
printf("\nBoth the names are same");
else
printf("\nThe names are different");


return 0;
}

int fnstrcmp(char *s1, char *s2)
{
for( ; *s1 != '\0' && *s2 != '\0' && *s1 == *s2 ; )
{
s1++;
s2++;
}

if(*s1 == *s2)
return 0;

return 1;
}

No comments:

Post a Comment

kiss on google ads if you are anonymous because your ip is trackable.thank you.

......from.admin