by writebetterc · 1y ago · 0 comments
Here's a much easier way to write the program:
1. Dump whole file into buffer as one string
2. Find newlines in buffer, replace with NULs. This also let's you find each line and save them in another buffer
3. Sort the buffer of all the lines you found
4. qsort the buffer
5. Print everything
6. Free both buffers
Or, as a C program: https://godbolt.org/z/38nq1MorM
... unless the file is too big to fit into memory?
You can always mmap the file instead and let the OS page in and out parts of the file, however :-).