#include <string.h> //#include <windows.h> /* uncomment this for Windows */ int strcmp (const char *s1, const char *s)
strcmp Compares 2 C strings.
If both strings are identical, the return value of strcmp is 0.
If the string s1 less than s2, the return value is less than 0,
and s1 is greater than s2, then the return value greater than 0
/* strcmp example code * http://code-reference.com/c/stdio.h/strcmp */ #include <stdio.h> /* including standard library */ //#include <windows.h> /* uncomment this for Windows */ #include <string.h> int main( void ) { char string1[5]="test"; char string2[6]="test2"; char string3[6]="test2"; /* string1 and string2 not compare */ if ( strcmp( string1, string2 ) == 0 ){ printf("same\n"); } else { printf("different\n"); } /* string1 and string2 not compare */ if ( strcmp( string2, string3 ) == 0 ){ printf("same\n"); } else { printf("different\n"); } return 0; }
user@host:~$ ./strcmp different same