Hi, I've tried searching several resources for info on this but I still don't quite understand what I need to do here. I'm new to C programming so please keep that in mind.
Basically what I want to do is read from a text file containing X number of lines, each with 3 elements where the characters are a 'name' for the ints, for example:
abc 123 45678
sdf 32002 12323
xcvssd 23 2234
adssp 324 1023
I then need to sort the data by int first and name second, and print it out in 2 tables
Field 1:
23 xcvssd
123 abc
324 adssp
32002 sdf
Field 2:
1023 adssp
2234 xcvssd
12323 sdf
45678 abc
I think what I need to do is create a struct, something like:
Code:
struct entry {
str field1[20]; /* Field lengths of 20 */
int field2[20];
int field2[20];
} database; /* Creates database variable of type entry*/
From there, I am confused as to how to sort the data. My thoughts are to to make a bubble sort function that will take in each element of the struct in one at a time and sort it. Should I just write over the sorted array/struct, or store it in a new array? Can I sort the entire struct at once?
I can't find any good examples of passing struct array element things into another function. Do I need to use pointers for this?
Does this sound like the right idea, or am I going about it all wrong? I'm not concerned about sorting speed or anything, I just want it to work for now.
Thanks!