Strcmp

Name

 * strcmp

Description
compares the string s1 with the string s2. The function returns 0, less than 0 or greater than 0, if S1 is equal to, less than or greater than s2, respectively.

Syntax
result = strcmp( *s1, *s2 );
 * s1 (constant pointer to char): First string.
 * s2 (constant pointer to char): Second string, to be compared with the first.
 * result (int): Result of camparing s1 with s2.

Example
void setup{ // Wait for the user to start the program... CDC.getKey; } void loop{ char *s1 = "Happy New Year"; char *s2 = "Happy New Year"; char *s3 = "Happy Holidays"; CDC.printf("strcmp(*s1,*s2) = %d\r\n", strcmp(s1,s2)); CDC.printf("strcmp(*s1,*s3) = %d\r\n", strcmp(s1,s3)); CDC.printf("strcmp(*s3,*s1) = %d\r\n", strcmp(s3,s1)); CDC.printf("Press any key to continue..."); CDC.getKey; }
 * 1) include 

Expected output:

strcmp(*s1,*s2) = 0 strcmp(*s1,*s3) = 1 strcmp(*s3,*s1) = -1 Press any key to continue...