1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
void print_strings(char const* label, char const* const* strings, size_t num_strings) {
printf("\n──────────────────────────────\n");
printf("%s\n", label);
for(int i = 0; i < num_strings; i++) {
printf("%s\n", strings[i]);
}
printf("\n");
}
int main(int argc, char* argv[]) {
// Which 'const' do we need to remove so that qsort(…) can reorder the elements?
// 1 2
// ↓ ↓
char const* const strings[] = { "charie", "bravo", "echo", "delta", "alpha" };
size_t size_of_one = sizeof(strings[0]);
size_t num_elements = sizeof(strings) / sizeof(strings[0]); // for static arrays ONLY
print_strings("BEFORE SORT", strings, num_elements);
qsort(strings, num_elements, size_of_one, compare_fn);
return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
|
© Copyright 2021 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.