aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ch5/5-14_rsort.c20
-rw-r--r--ch5/5-15_sort-fold.c25
-rw-r--r--ch5/5-16_dir-order.c30
3 files changed, 51 insertions, 24 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++;
+ }
}
}
}
diff --git a/ch5/5-15_sort-fold.c b/ch5/5-15_sort-fold.c
index 3b508b9..90b567b 100644
--- a/ch5/5-15_sort-fold.c
+++ b/ch5/5-15_sort-fold.c
@@ -142,14 +142,23 @@ int main (int argc, char *argv[]) {
int fold = 0; /* 1 if folding upper and lower case */
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;
- } else if (strcmp(argv[i], "-f") == 0) {
- fold = 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;
+ case 'f':
+ fold = 1;
+ break;
+ }
+ j++;
+ }
}
}
}
diff --git a/ch5/5-16_dir-order.c b/ch5/5-16_dir-order.c
index eabf755..7533b3b 100644
--- a/ch5/5-16_dir-order.c
+++ b/ch5/5-16_dir-order.c
@@ -162,16 +162,26 @@ int main (int argc, char *argv[]) {
int nlines; /* number of input lines read */
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;
- } else if (strcmp(argv[i], "-f") == 0) {
- fold = 1;
- } else if (strcmp(argv[i], "-d") == 0) {
- dir = 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;
+ case 'f':
+ fold = 1;
+ break;
+ case 'd':
+ dir = 1;
+ break;
+ }
+ j++;
+ }
}
}
}