Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.