I've got an array of char*
in a file.
The company I work for stores data in flat files.. Sometimes the data is sorted, but sometimes it's not.
I'd like to sort the data in the files.
Now I could write the code to do this, from scratch. Is there an easier way?
Of course an in-place sort would be the best option. I'm working on large files and have little RAM. But I'll consider all options.
All strings are the same length.
This is some sample data:
the data is of fixed length
the Data is of fixed length
thIS data is of fixed lengt
This would represent three records of length 28. The app knows the length. Each record ends with CRLF (\r\n
), though it shouldn't matter for this sort.
template<size_t length> int less(const char* left, const char* right) {
return memcmp(left, right, length) < 0;
}
std::sort(array, array + array_length, less<buffer_length>);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With