I want to use fread or something similar in a strange way. I am not sure whether it is possible or not... Let me explain the case:
I have a binary file, named "dummy". This file contains unsigned char array in it. However, I want to take them into a float array which will store 4x memory space.
I can achieve my goal like the following:
FILE* in_file;
int numberOfCharacters = 1000; // number of unsigned characters to read ...
in_file = fopen("dummy", "rb");
float* floatArray = (float*) malloc( numberOfCharacters * sizeof(float) );
for(int i=0;i<numberOfCharacters;i++)
{
unsigned char temp;
fread(&temp, sizeof(unsigned char), 1, in_file);
floatArray[i] = temp;
}
I know (actually didn't really try) this way will probably work. But I'm curious whether is there a better (faster) way of doing it? Maybe, without a loop..?
Thanks in advance,
Sait.