Comparing Strings

Lab C Beginner 10 points

Read two words and print equal, or which one comes first alphabetically (A comes first), using strcmp.

Input

Two words.

Output

One line.

Example

Input

apple banana

Output

apple comes first
Sample input available Sample output available
Editor
C

Hints

strcmp returns 0 if equal, negative if the first is smaller.

Solution explanation

a == b compares addresses, not text - always use strcmp.

Show solution
#include <stdio.h>
#include <string.h>

int main() {
    char a[50], b[50];
    scanf("%s %s", a, b);
    int r = strcmp(a, b);
    if (r == 0) printf("equal\n");
    else if (r < 0) printf("%s comes first\n", a);
    else printf("%s comes first\n", b);
    return 0;
}
Output
Answer
HOME LEARN COMMUNITY DASHBOARD