/* File: compare2.c Use string library comparison function */ #include #include #include #include int main() { char *str1, *str2 ; int r ; str1 = readline("First string: ") ; str2 = readline("Second string: ") ; r = strcmp(str1, str2) ; if (r < 0) { printf("\"%s\" is alphabetically before \"%s\"\n", str1, str2) ; } else if (r > 0) { printf("\"%s\" is alphabetically after \"%s\"\n", str1, str2) ; } else { printf("\"%s\" is the same as \"%s\"\n", str1, str2) ; } free(str1) ; free(str2) ; return 0 ; }