From f5902e699f4692fd7b854c63dccfa79963e66926 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Tue, 29 May 2012 16:52:13 -0400 Subject: [PATCH] One more goofy modification to `temperatures` practice prog before moving on to something more fun. --- gnu-c/temperatures.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/gnu-c/temperatures.c b/gnu-c/temperatures.c index 6e341c2..a185598 100644 --- a/gnu-c/temperatures.c +++ b/gnu-c/temperatures.c @@ -14,11 +14,12 @@ double f2c(double fahrenheit) { } -void usage(const char *prog, const char *msg) { - fprintf(stderr, "Usage: %s [fFcC]\n", prog); +void die_usage(const char *prog, const char *msg) { + fprintf(stderr, "Usage: %s [FC]\n", prog); if (msg != NULL) { fprintf(stderr, "%s\n", msg); } + exit(EXIT_FAILURE); } @@ -33,8 +34,7 @@ int main(int argc, char * argv[]) { const char *temp_string; if (argc < 2) { - usage(prog, NULL); - exit(EXIT_FAILURE); + die_usage(prog, NULL); } if (((int)strlen(argv[1]) == 1) && (argv[1][0] == '-')) { @@ -45,28 +45,23 @@ int main(int argc, char * argv[]) { } if ((ret == 0) || (ret == EOF)) { - usage(prog, "No temperature provided!"); - exit(EXIT_FAILURE); + die_usage(prog, "No temperature provided!"); } if (ret == 1) { - usage(prog, "No scale provided!"); - exit(EXIT_FAILURE); + die_usage(prog, "No scale provided!"); } switch (scale) { - case 'c': case 'C': printf(out_fmt, c2f(temp), 'F'); break; - case 'f': case 'F': printf(out_fmt, f2c(temp), 'C'); break; default: sprintf(msg, "Unknown scale: '%c'", scale); - usage(prog, msg); - break; + die_usage(prog, msg); } exit(EXIT_SUCCESS);