← C-Strings

String Equality Without strcmp

medium

Implement string equality yourself, without calling strcmp. This is worth doing by hand once specifically because the natural-looking wrong answer is subtle: it’s not enough to compare characters until one string’s terminator shows up and declare victory if nothing mismatched along the way. "cat" and "cats" share every character in "cat"’s length – if your loop only checks for mismatches up to the shorter string’s end, it’ll wrongly call them equal. The fix is checking, after the comparison loop, that both strings hit '\0' at the exact same position – if one is still going, they’re different lengths, and can’t be equal no matter how much of a shared prefix they have.

Your solution

"Run" uses the sample stdin ("cat cat"). "Submit" checks your code against all 4 test cases.

Test results

Submit your solution to run it against all test cases.

Hints

    Reference solution