diff options
author | zlg <zlg@zlg.space> | 2014-05-21 05:54:51 -0500 |
---|---|---|
committer | zlg <zlg@zlg.space> | 2014-05-21 05:54:51 -0500 |
commit | cb197e459c381591f9cb0a92a0cbd720bdbda5a7 (patch) | |
tree | 6894d07c67403933b7d48fd71d5c49cfcc639a41 /ch5/5-14_rsort.c | |
parent | Solve Exercise 5-16: directory-ordered `tail` (diff) | |
download | knr-cb197e459c381591f9cb0a92a0cbd720bdbda5a7.tar.gz knr-cb197e459c381591f9cb0a92a0cbd720bdbda5a7.tar.bz2 knr-cb197e459c381591f9cb0a92a0cbd720bdbda5a7.tar.xz knr-cb197e459c381591f9cb0a92a0cbd720bdbda5a7.zip |
Refactor flag handling
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++; + } } } } |