samedi 31 octobre 2015

Trying to read back binary data from a file, causing crash

thanks in advance for your help.

I'm trying to call a function which will read back date from the binary file I've just created of a sine wave. The file has already been opened in w+b in the main function. I want to copy the data to my buffer array, then print them out.

end_time is the total number of samples in the file. The samples have been written as floats. Code Blocks gives no errors, but the program crashes when it gets to this point and I'm not sure why.

void printwave(FILE *fp, int end_time)
   int i;

   float buffer[end_time];
   fseek(fp, 0, SEEK_SET);

   for(i=0; i==end_time; i++)
        fread(buffer, sizeof(float), 1, fp);
        printf("%d\t%.2f\n", i, buffer[i]);


Thanks for your help, Andy.

Aucun commentaire:

Enregistrer un commentaire