diff options
Diffstat (limited to '')
-rw-r--r-- | ch5/5-14_rsort.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/ch5/5-14_rsort.c b/ch5/5-14_rsort.c index 4c03191..b39a20c 100644 --- a/ch5/5-14_rsort.c +++ b/ch5/5-14_rsort.c @@ -129,12 +129,20 @@ int main (int argc, char *argv[]) { int reverse = 0; /* 1 if reverse sort */ if (argc > 1) { - int i; - for (i = 1; --argc; i++) { - if (strcmp(argv[i], "-n") == 0) { - numeric = 1; - } else if (strcmp(argv[i], "-r") == 0) { - reverse = 1; + int i, j; + for (i = 1, j = 0; --argc; i++) { + if (argv[i][j++] == '-') { + while (argv[i][j] != '\0') { + switch(argv[i][j]) { + case 'n': + numeric = 1; + break; + case 'r': + reverse = 1; + break; + } + j++; + } } } } |