C-Strcmp()
function
It refers to string comparison function.
The general
format of strcmp() function is:
Syntax: strcmp(string1
, string2);
Function is used to compare the given two strings.
Function performs comparison between two strings character
by character until there is a mismatch or end of the strings is reached,
whichever occurs first. If the two
strings are identical, function returns 0 value. If they are not identical, function returns
numerical difference between the ASCII values of the first non-matching
characters.
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main ()
{
char s1[20],s2[20];
int c;
puts(“Enter String1”);
gets(s1);
puts(“Enter String2”);
gets(s2);
c=strcmp(s1, s2);
if (c = = 0)
printf (“String are equal);
else
printf("String are Not equal");
}
#include <conio.h>
#include <string.h>
void main ()
{
char s1[20],s2[20];
int c;
puts(“Enter String1”);
gets(s1);
puts(“Enter String2”);
gets(s2);
c=strcmp(s1, s2);
if (c = = 0)
printf (“String are equal);
else
printf("String are Not equal");
}
No comments:
Post a Comment