Writing a program in C that is similar to ls. My program needs to implement the -S flag, meaning it sorts whatever directory is specified (or the current one if not) by the size of its contents in bytes.
Obviously you can easily do an alphabetical sorting with scandir and alphasort (see https://www.cs.cf.ac.uk/Dave/C/node20.html). My question is whether you can use scandir with a comparator function that compares two entries on the size of their contents.
Alternatively, I could just specify NULL for the comparator function, have the unsorted array, and then sort it myself with the qsort() function.
Any advice much appreciated. Any clarifications needed, just say in the comments.