// this is my union......
union URec {
structA astruct; //union cont. 3 structs
structB bstruct;
structC cstruct;
};
union URec Data;
// The unions are held on a binary file and require reading into an array to be sorted before being written to a text file. The arrays are sorted in ascending order of the the second field of each structure.
I have used the following code to try to achieve this but I am not sure about how to sort the array or how to write it to the text file.
Any help, ideas or criticism(constructive) would be hugely appreciated.
infile.seekp(0, ios::end);
totnum = infile.tellg(); // No. of bytes in file
elements = totnum / sizeof(Data); //No of unions in file
URec *code_ptr;
code_ptr = new URec [elements]; //assign new memory
// read unions into array
infile.read((char *)code_ptr,sizeof(elements * sizeof(Data)));
// start sorting ????????????