Add argument parsing
parent
8ec844245a
commit
369cafe0c1
16
main.c
16
main.c
|
@ -73,8 +73,20 @@ static int get_input(int num_threads, struct input **res) {
|
|||
|
||||
int main(int argc, char *argv[]) {
|
||||
struct input *inputs = NULL;
|
||||
// TODO: Get input to get actual number of inputs. 5 is just for funzies.
|
||||
int num_inputs = get_input(5, &inputs);
|
||||
if (argc < 2 || argc > 3) {
|
||||
printf("%s\n", USAGE_STRING);
|
||||
return -1;
|
||||
} else if (argc == 3) {
|
||||
printf("Not yet implemented.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int num_threads = strtol(argv[1], NULL, 10);
|
||||
if (errno == ERANGE || (num_threads == 0 && errno == EINVAL)) {
|
||||
printf("Invalid number of threads.\n");
|
||||
}
|
||||
|
||||
int num_inputs = get_input(num_threads, &inputs);
|
||||
for (int i = 0; i < num_inputs; i++) {
|
||||
printf("#%d recipient=%d value=%d\n", i, inputs[i].recipient, inputs[i].value);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue