sudhir said:
hi
My application receives daily records, I need to show it sorted if
needed...but I am not finding the right direction to do that...
Here's the basic approach...
a) Define a struct type to represent a record of the file
b) Read the file and split each record into the correct struct fields,
storing it in an array (or other data structure) of the structs.
c) Write a comparison function that determines an ordering between two
given records, possibly based on a configurable choice of column
priorities. The function prototype should be
int foo(const void *a, const void *b);
where it takes pointers to the data, and returns -1, 0, or 1 to
signify less, equal or greater respectively.
d) Sort the data using the comparison function. If you chose an array,
you can just use the standard qsort function here.
Let us know if you're having trouble with any of those points, post a
complete and compilable example, and we will be happy to help you further.