Hacker News new | ask | show | jobs
by ummonk 1510 days ago
I don’t think you realize how much harder this becomes with C. You probably need to can’t just add strings to an array you’ll need to allocate space for all the arrays (presumably by doing a first pass to determine CSV dimensions) and all the substrings (since they’re Cstrings).

Personally I’d do it by storing indexes into the CSV contents instead of using null terminated C strings.

Doing all of this in just 15 minutes is going to be hard.

By the way, your solution as described is wrong, since it sorts each row independently. What you’d need to do is store all the data in a transposed format i.e an array of pointers to column arrays, then sort the array by giving qsort a comparison function that looks at the first entry in each column.