Improvements to expseq help text
Getty Ritter
11 years ago
2 | 2 | #include <stdio.h> |
3 | 3 | #include <stdlib.h> |
4 | 4 | |
5 | #define HELPMSG "USAGE: expseq LAST\n or: expseq FIRST LAST\n or: expseq --help\n"\ | |
6 | "Print numbers 2^FIRST to 2^LAST in exponential steps.\n\n"\ | |
7 | "If FIRST is omitted, it defaults to 0.\n" | |
8 | ||
5 | 9 | int main(int argc, char* argv[]) |
6 | 10 | { |
7 |
int fstnum = 0, lstnum |
|
11 | int fstnum = 0, lstnum, i; | |
8 | 12 | if (argc == 2) { |
9 | char* endptr = argv[1]; | |
10 | lstnum = strtol(argv[1], &endptr, 10); | |
11 | if (!endptr) { | |
12 | fprintf(stderr, "%s: non-numeric arg: %s\n", argv[0], argv[1]); | |
13 | return 0; | |
14 | } | |
13 | if (strcmp(argv[1], "--help")==0 | |
14 | || strcmp(argv[1], "-h")==0) { | |
15 | fprintf(stderr, HELPMSG); | |
16 | return 1; | |
17 | } else { | |
18 | char* endptr = argv[1]; | |
19 | lstnum = strtol(argv[1], &endptr, 10); | |
20 | if (!endptr) { | |
21 | fprintf(stderr, "%s: non-numeric arg: %s\n", argv[0], argv[1]); | |
22 | return 1; | |
23 | } | |
24 | } | |
15 | 25 | } else if (argc == 3) { |
16 | 26 | char* endptr = argv[1]; |
17 | 27 | fstnum = strtol(argv[1], &endptr, 10); |
18 | 28 | if (!endptr) { |
19 | 29 | fprintf(stderr, "%s: non-numeric arg: %s\n", argv[0], argv[1]); |
20 |
return |
|
30 | return 1; | |
21 | 31 | } |
22 | 32 | endptr = argv[2]; |
23 | 33 | lstnum = strtol(argv[2], &endptr, 10); |
24 | 34 | if (!endptr) { |
25 | 35 | fprintf(stderr, "%s: non-numeric arg: %s\n", argv[0], argv[2]); |
26 |
return |
|
36 | return 1; | |
27 | 37 | } |
28 | 38 | } else { |
29 | 39 | fprintf(stderr, "%s: missing operand\n", argv[0]); |
30 |
return |
|
40 | return 1; | |
31 | 41 | } |
32 |
i |
|
42 | i = fstnum; | |
33 | 43 | while (i <= lstnum) { |
34 | 44 | printf("%d\n", (int) pow(2, (float) i)); |
35 | 45 | i++; |