Hi,
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...
Code:
unsigned char *myArray = (unsigned char*)malloc(sizeof(unsigned char)*size);
I then read from the file into the array of unsigned chars using the following code...
Code:
int c = 0;
while (c<=size)
{
fread(&myQta[c], 1, 1, fp);
c++;
}
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?
Regards,
Bc2005