diff --git a/src/strcmp.c b/src/strcmp.c index 784029c..33eab10 100644 --- a/src/strcmp.c +++ b/src/strcmp.c @@ -30,10 +30,11 @@ int main(int argc, char *argv[]){ return EX_USAGE; } - for (; *argv[1] != '\0'; ++argv[1]) { /* iterate chars in ref */ - /* iterate argc */ - for (size_t i = 2 /* ref cmp */; i < argc; ++argv[i], ++i) { - /* this doesn't overrun because of nul termination */ + /* This compares the Nth character of arg[2] onward with argv[1]'s Nth + * character, rather than comparing each arg with argv[1] sequentially. */ + for (; *argv[1] != '\0'; ++argv[1]) { /* iterate chars in argv[1] */ + for (size_t i = 2; i < argc; ++argv[i], ++i) { /* iterate &argv[2] */ + /* this never overruns because of nul termination */ if (*argv[i-1] != *argv[i]) { return *argv[i-1] - *argv[i]; } } }