diff options
author | olivier gayot <ogayot@free.fr> | 2012-12-13 11:54:29 +0000 |
---|---|---|
committer | olivier gayot <ogayot@free.fr> | 2012-12-13 11:54:55 +0000 |
commit | eeb456d954b90c8f1c9247d91afde52d690778ff (patch) | |
tree | b9429e363482202bd4b905cb3ff6f1bbeeb71b95 /main.c | |
parent | 88ba8ead742537c369c228953a2b2a88efd021f5 (diff) |
le_compte_est_bon: make the solver work with any number of arguments
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 26 |
1 files changed, 14 insertions, 12 deletions
@@ -4,23 +4,25 @@ int main(int argc, char **argv) { + const char *arg0 = *argv++; vect_t vect; - if (argc != 8) { - puts("takes exactly 7 args"); - return -1; + if (argc < 3) + goto usage; + + vect.len = argc - 2; + vect.array = malloc(sizeof(int) * vect.len); + + for (int i = 0; i < (signed)vect.len; ++i) { + vect.array[i] = atoi(*argv++); } - vect.array = malloc(sizeof(int) * 6); - vect.array[0] = atoi(argv[1]); - vect.array[1] = atoi(argv[2]); - vect.array[2] = atoi(argv[3]); - vect.array[3] = atoi(argv[4]); - vect.array[4] = atoi(argv[5]); - vect.array[5] = atoi(argv[6]); - vect.len = 6; - solve(&vect, atoi(argv[7])); + solve(&vect, atoi(*argv)); free(vect.array); return 0; + +usage: + fprintf(stderr, "Usage: %s number ... result\n", arg0); + return -1; } |