basics · beginner · ~15 min

Strings equal

Use the sign convention of strcmp.

Challenge

Test two strings for equality using the standard strcmp.

Task

Implement int str_eq(const char *a, const char *b) that returns 1 if a and b are equal, else 0. You may call strcmp (which returns 0 exactly when the strings match). No main — the grader calls it.

Input

Two NUL-terminated strings a and b.

Output

Returns 1 if the strings are equal, otherwise 0.

Example

str_eq("abc", "abc")   ->   1
str_eq("abc", "abd")   ->   0
str_eq("", "")         ->   1

Edge cases

  • Two empty strings are equal.

Input format

Two NUL-terminated strings a and b.

Output format

1 if equal, otherwise 0.

Constraints

Using strcmp is allowed.

Starter code

#include <string.h>

int str_eq(const char *a, const char *b) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.