diff options
author | Daniel Santos <dacs.git@brilhante.top> | 2022-03-12 16:32:13 +0000 |
---|---|---|
committer | Daniel Santos <dacs.git@brilhante.top> | 2022-03-12 16:32:13 +0000 |
commit | a1447b807b302e48beeb85a61a1f036db2f5ff77 (patch) | |
tree | 3df2ee89a705db2d9270544d9f6c0c270484f673 | |
parent | 90c869857b55782d4d6b21434a58da4d2f9e6be3 (diff) | |
download | numericx-c-a1447b807b302e48beeb85a61a1f036db2f5ff77.tar.gz |
static program name (macro)
* make program name into the macro PROG_NAME * add program name into all error messages Signed-off-by: Daniel Santos <dacs.git@brilhante.top>
-rw-r--r-- | numericx.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/numericx.c b/numericx.c index 2870b13..b8c0254 100644 --- a/numericx.c +++ b/numericx.c @@ -4,6 +4,8 @@ #include <stdbool.h> #include <errno.h> +#define PROG_NAME "numericx" + #ifndef DEBUG #define DEBUG false #endif @@ -39,8 +41,6 @@ typedef struct NumeralPtr struct NumeralPtr *previous; } numeral_ptr; -char* program_name = NULL; - /* * Creates new digit for numeral_ptr * Return pointer to new numeral_ptr @@ -52,7 +52,7 @@ new_digit(numeral_ptr* last_numeral, char const* to_first) numeral_ptr* starting_point = malloc(sizeof(numeral_ptr)); if(starting_point == NULL) { - fprintf(stderr, "error: %s: %s!", program_name, strerror(ENOMEM)); + fprintf(stderr, "error: %s: %s!", PROG_NAME, strerror(ENOMEM)); return NULL; } @@ -210,12 +210,10 @@ free_numeral(numeral_ptr* numeral) int main(int argc, char* argv[]) { - program_name = argv[0]; - /* argument processing */ if( !(argc == 2) ) { - fprintf(stderr, "usage: %s <number>\n", program_name); + fprintf(stderr, "usage: %s <number>\n", PROG_NAME); exit(EXIT_FAILURE); } @@ -234,7 +232,7 @@ main(int argc, char* argv[]) { free(from); free(to); - fprintf(stderr, "error: %s.\n", strerror(EDOM)); + fprintf(stderr, "error: %s: %s.\n", PROG_NAME, strerror(EDOM)); exit(EDOM); } @@ -272,7 +270,7 @@ main(int argc, char* argv[]) free(to); free_numeral(counting); free_numeral(result); - fprintf(stderr, "error: unrepresentable void number\n"); + fprintf(stderr, "error: %s: unrepresentable void number\n", PROG_NAME); exit(EXIT_FAILURE); } decrement_number_string(number, from_first, from_last, from_first); |