Syntax
#include <string.h> int strcmp(const char *string1, const char *string2);Description
strcmp compares the strings pointed to by string1 and string2. The function operates on null-terminated strings. The string arguments to the function should contain a null character (\0) marking the end of the string.
strcmp returns a value indicating the relationship between the two strings, as follows: compact break=fit.
Value
This example compares the two strings passed to main using strcmp.
#include <stdio.h>#include <string.h> int main(int argc,char **argv) { int result; if (argc != 3) { printf("Usage: %s string1 string2\n", argv[0]); } else { result = strcmp(argv[1], argv[2]); if (0 == result) printf("\"%s\" is identical to \"%s\"\n", argv[1], argv[2]); else if (result < 0) printf("\"%s\" is less than \"%s\"\n", argv[1], argv[2]); else printf("\"%s\" is greater than \"%s\"\n", argv[1], argv[2]); } return 0; /**************************************************************************** If the following arguments are passed to this program: "is this first?" "is this before that one?" The output should be: "is this first?" is greater than "is this before that one?" ****************************************************************************/ }Related Information