Tuesday, April 30, 2013

c Program to Compare Two Strings using strcmp()


/*Program to Compare Two Strings using strcmp() /
#include <stdio.h>
#include <string.h>
main()                        
{
char s1[20], s2[20];
int result;
printf("\nEnter first string: ");
gets(s1);
printf("\nEnter second string: ");
gets(s2);
result = strcmp(s1, s2);
if (result == 0)
printf("\nBoth strings are equal");
else
printf("\nBoth strings are not equal");
getch();
}

String comparison is the process of comparing whether two strings  are same or not.The function which used for this purpose is strcmp(). strcmp() is defined in 'string.h'. It's syntax is
strcmp(first string,second string);
If the two strings are equal ,it returns '0' . By using an if condition ie
if(value == 0),we get the answer...

No comments:

Post a Comment