From b1c1bd880f126eab3fbf0fe5a7391dbcb8d4b53e Mon Sep 17 00:00:00 2001 From: Ethanell Date: Wed, 18 Dec 2019 17:30:34 +0100 Subject: [PATCH] Optimisation and fix args --- map.c | 57 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/map.c b/map.c index 868c805..48f1c35 100644 --- a/map.c +++ b/map.c @@ -1,47 +1,52 @@ #include "map.h" int main(int argc, char **argv) { - if (argc < 7 || argc > 7) { + if (argc != 7) { printf("Not enough arguments !\n"); return 1; } - if (!isdigit(*argv[1]) || !isdigit(*argv[2]) || !isdigit(*argv[5])) { - printf("Invalid arguments !\n"); - return 1; - } - int l = atoi(argv[1]), c = atoi(argv[2]), op = atoi(argv[5]); - char e = *argv[3], o = *argv[4], f = *argv[6]; - char **tab; - if (!(tab = calloc(l, sizeof(char*)))) { - printf("Allocation fail !\n"); - return 1; - } - for (unsigned int i=0; i op) { - tab[i][j] = e; + line[j] = e; } else { - tab[i][j] = o; + line[j] = o; } } - } - printf("%d %c %c %c\n", l, e, o, f); - printf("%d %d\n", c, op); - for (unsigned int i=0; i