HELP! Trying to load a binary file on ce3.00 - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

HELP! Trying to load a binary file on ce3.00

Hi,

I'm having trouble trying to scan in a binary file in CE. my code is below. Every time I set the b format, fscanf bombs out. Please help.

FILE *fp;
char data;
char * dspSource = NULL;
unsigned int length; //the file length
unsigned int i;
tdrError error;

//get the length of the file
fp = fopen(FILE_DSP_SOURCE, "rb");

if (fp != NULL)
{
while (fscanf(fp, "%c", data)!= EOF)//bombs here
{
length++;
}
fclose(fp);
}
else
{
error = ERR_FILE_NOT_FOUND;
}

dspSource = (char *)malloc(length * sizeof(char));

//copy dsp code to memory
fp = fopen(FILE_DSP_SOURCE, "rb");

if (fp != NULL)
{
for (i=0; i<length; i++)
{
fscanf(fp, "%c", data);
dspSource[i] = data;
}
fclose(fp);
}
else
{
error = ERR_FILE_NOT_FOUND;
}

Cheers,

Scott
Sign In or Register to comment.