strcmp function : string.h >> Compare two strings
Contents
strcmp function >> string.h >> Compare two strings
What strcmp Actually Does ?
- Function takes two Strings as parameter
- It returns integer .
What strcmp Actually Does ?
- Function takes two Strings as parameter
- It returns integer .
Syntax :
int strcmp ( char *s1, char *s2 ) ;
Return Type
Return Type | Condition |
---|---|
-ve Value | String1 < String2 |
+ve Value | String1 > String2 |
0 Value | String1 = String2 |
Live Example 1 : Two strings are Equal
char s1[10] = "SAM",s2[10]="SAM" ; int len; len = strcmp (s1,s2); if (len == 0) printf ("Two Strings are Equal");
Live Example 2 : String1 is Greater than String2
char s1[10] = "SAM",s2[10]="sam" ; int len; len = strcmp (s1,s2); printf ("%d",len); //-ve value