I have an array of floats that I want to output to a file in binary. My relevant code is as follows:
FILE *binFile;
binFile = fopen(fileName, "wb");
if (binFile)
{
fwrite(completeList, sizeof(float), size, binFile);
}
Now, completeList is a pointer to an array of floats I was talking about, and size is another parameter I'm passing it indicating how many elements there are.
When this is outputted to a binary file, opening that file shows a bunch of random ASCII characters. I know this is what I should expect, but when I put it through a hex editor it shows random crap.
What am I doing wrong?
EDIT:
My parsing code:
FILE *bofFile = fopen(file, "rb");
if(bofFile)
{
float *tempArray;
fseek(bofFile, 0, SEEK_END);
unsigned long int size = ftell(bofFile) / sizeof(float);
tempArray = (float *)malloc(size);
fread(tempArray, sizeof(float), size, bofFile);
std::cout << tempArray[0];
}