strcmp(1): code clarification
This commit is contained in:
parent
efb3ce626d
commit
becb3bac4e
@ -30,10 +30,11 @@ int main(int argc, char *argv[]){
|
|||||||
return EX_USAGE;
|
return EX_USAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; *argv[1] != '\0'; ++argv[1]) { /* iterate chars in ref */
|
/* This compares the Nth character of arg[2] onward with argv[1]'s Nth
|
||||||
/* iterate argc */
|
* character, rather than comparing each arg with argv[1] sequentially. */
|
||||||
for (size_t i = 2 /* ref cmp */; i < argc; ++argv[i], ++i) {
|
for (; *argv[1] != '\0'; ++argv[1]) { /* iterate chars in argv[1] */
|
||||||
/* this doesn't overrun because of nul termination */
|
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]; }
|
if (*argv[i-1] != *argv[i]) { return *argv[i-1] - *argv[i]; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user