I have created a routine within a C program to load some data from a binary file. The method I am using at the moment is unreliable and slow, and was wondering if there was any way of optimising it?
I simply open for the file for reading in binary mode and allocate a pointer to an array of unsigned chars - the array size is dependant upon the size of the file. The array is declared as the following...
I then read from the file into the array of unsigned chars using the following code...
unsigned char *myArray = (unsigned char*)malloc(sizeof(unsigned char)*size);
The code above simply reads a value one at a time from the file into the array. The method used above works fine and the file is fully loaded into the array. Is there anyway of optimising the load while loop above into something more efficient?
int c = 0;
fread(&myQta[c], 1, 1, fp);