diff options
author | Robby Zambito <contact@robbyzambito.me> | 2021-10-03 21:42:49 -0400 |
---|---|---|
committer | Robby Zambito <contact@robbyzambito.me> | 2021-10-03 21:42:49 -0400 |
commit | 905d799f527ef60470c0e80e41b720d9b265b90f (patch) | |
tree | de5c35560cc5ed8bf64b0c0879da5b27aa19be9a | |
parent | 1676ad3c902d600c3aabdcd5817b02fffa655f38 (diff) |
Sort indices after parsing them.
When we use the indices we assume they are sorted. This makes sure they
are sorted, rather than assuming the user entered them in order.
-rw-r--r-- | src/todo.c | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -135,6 +135,18 @@ void todo_add(int argc, char **argv) { fclose(todo_file); } +static int int_compare(const void *a, const void *b) { + int int_a = *((int *)a); + int int_b = *((int *)b); + + if (int_a == int_b) + return 0; + else if (int_a < int_b) + return -1; + else + return 1; +} + static size_t *parse_indices(int argc, char **argv) { size_t *res = calloc(sizeof(size_t), argc); @@ -147,6 +159,7 @@ static size_t *parse_indices(int argc, char **argv) { } } + qsort(res, argc, sizeof(size_t), int_compare); return res; } |