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);