/* File: compare1.c Use string library comparison function */ #include #include int main() { char str1[100], str2[100] ; char cr ; int r ; printf("First string: ") ; scanf("%[^\n]s", str1) ; // read until newline scanf("%c", &cr) ; // advance past newline character printf("Second string: ") ; scanf("%[^\n]s", str2) ; // read until newline scanf("%c", &cr) ; // advance past newline character 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) ; } return 0 ; }