diff options
author | Hampus <hampus@hampusmat.com> | 2021-01-07 22:11:34 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2021-12-11 19:55:06 +0100 |
commit | fba725092a4b51783e73075c60a15c544e82fb80 (patch) | |
tree | b221d726618037b6ec85c6cd786a93a3608685ab | |
parent | 397cf44cc599430e8fe74b6daf59cfe02781081a (diff) |
refactor: improve width & height argument parsing
-rw-r--r-- | mazerator.c | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/mazerator.c b/mazerator.c index 6c24ec0..9b2e434 100644 --- a/mazerator.c +++ b/mazerator.c @@ -123,20 +123,15 @@ int main(int argc, char *argv[]) while((c = getopt_long(argc, argv, "w:h:W:s:", options, NULL)) != -1) { switch(c){ case 'w': - // Set Width - if(is_number(optarg) && atoi(optarg) >= 1 && atoi(optarg) <= 255) - maze_width = atoi(optarg); - else{ - printf("Invalid option argument for -w/--width!\n"); - exit(1); - } - break; case 'h': - // Set heigth + // Set heigth or width if(is_number(optarg) && atoi(optarg) >= 1 && atoi(optarg) <= 255) - maze_heigth = atoi(optarg); + switch(c){ + case 'h': maze_heigth = atoi(optarg); + case 'w': maze_width = atoi(optarg); + } else{ - printf("Invalid option argument for -h/--heigth!\n"); + printf("Invalid option argument for -%c!\n", c); exit(1); } break; |