Compares two character strings.
#include <string.h> int strcmp(const char *s1, const char *s2);
s1
The string to compare.
s2
The comparison string.
This function compares the character array pointed to by s1 to the character array pointed to by s2. The function starts at the beginning of each and stops the comparison when it reaches a null character in s1 or s2. Both strings must be null terminated character arrays. The function returns:
This facility may not be available on some configurations of the EWL.
#include <string.h> #include <stdio.h> #define MAX 20 int main (void) { char s1[] = "butter"; char s2[] = "olive oil"; char dest[MAX]; if (strcmp(s1, s2) < 0) strcpy(dest, s2); else strcpy(dest, s1); printf(" s1=%s\n s2=%s\n dest=%s\n", s1, s2, dest); return 0; } Output: s1=butter s2=olive oil dest=olive oil