basics · beginner · ~15 min
Compare two strings character by character.
Compare two strings for exact equality, without using the library.
Implement int str_equal(const char *a, const char *b) that returns 1 if a and b are identical strings, else 0. Do not call strcmp — compare character by character. No main — the grader calls it.
Two NUL-terminated strings a and b.
Returns 1 if the strings are identical, otherwise 0.
str_equal("abc", "abc") -> 1
str_equal("abc", "abd") -> 0
str_equal("ab", "abc") -> 0 (b is a prefix, not equal)
str_equal("", "") -> 1
strcmp — walk both strings yourself.Two NUL-terminated strings a and b.
1 if identical, otherwise 0.
Do not call strcmp.
int str_equal(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.