Sunday, 15 September 2013

sorting based on key from a file

sorting based on key from a file

I need to sort stuff read from a file similar to the following:
Key: 2 rec:1 2 3 4 5 6 ...
Key: 3 rec:7 8 9 10 11 ...
Key: 1 rec:A B C D E F ...
becomes
Key: 1 rec:A B C D E F ...
Key: 2 rec:1 2 3 4 5 6 ...
Key: 3 rec:7 8 9 10 11 ...
and if we have something unsorted in rec (record ) of a key, it will
remain unchanged! as sorting is based on the key. I want to use qsort()
defined in C for sorting. I have an idea to use strtok for breaking each
line read from file into manageable arrays but I am not if it's the best
way to find the key number so as to sort them with qsort from C library.
P.S.: Each line of the input file includes one key like Key: 1 rec:A B C D
E F ... Also we won't sort records within a key.

No comments:

Post a Comment