I have two arrays, the first one only contains the name of the files I’m using and the second contains the first record of each one:
typedef struct{
unsigned long long id;
unsigned long long unixDate;
char name[30];
float prom;
} TAlumn;
char fileNames[5][20] = {
"alumn1.dat",
"alumn2.dat",
"alumn3.dat",
"alumn4.dat",
"alumn5.dat"
};
TAlumn firstsRecs[5];
I want to sort the array “firstsRecs” based on “unixDate” but at the same time, sort the “fileNames” array.
i.e. if the 3rd record in “firstRecs” is moved to the first position, “alum3.dat” should also be moved to the first position.
I thought about using an array of struct with the filename and the first record and then sort that array:
typedef struct {
char fileName[20];
void *firstRec;
} TSort;
but the function to sort that array has to be generic so the firstRec has to be void * (and I assume, stored in a malloc), but if the quantity of files is not fixed (it could be 1,2,3, etc), how can I use malloc if I don’t know the exact number of files?