I'm trying to decrement a FILE pointer in C , but I don't get it done, here is my code:
#include <math.h>
#include <stdio.h>
#include <complex.h>
int main() {
FILE* inputFile = NULL;
double* inputData = NULL;
unsigned int windowSize = 512;
unsigned int index1 = 0, index2 = 0, i = 0;
double temp = 0.0;
// mememory allocation
inputData = (double*) malloc(sizeof(double)*windowSize);
// Opning files
inputFile = fopen(" file","rb");
if (inputFile == NULL) {
printf("Couldn't open either the input or the output file \n");
return -1;
}
while((i=fread(inputData,sizeof(double),windowSize,inputFile))==windowSize){
for (index1 =0; index1 < windowSize;index1++) {
printf("index %d \t %d %d\t %lf\n",index1,index2,i,inputData[index1]);
fprintf(outputFile,"%lf ",inputData[index1]);
}
index2++;
}
// I need to start read from the end of the file - the value of i
printf( " the last i %d \n", i);
inputFile-i;
while (!(feof(inputFile))) { // the program doesnt'T get into the loop
fread(&temp,sizeof(double),1,inputFile);
printf("\n\n %lf \n",temp);
}
fclose(inputFile);
}
any idea idea how may I do this?
UPDATE
I ve changed the code based on doc of fseek
like :
i=i*-1;
printf( " the last i %d \n", i);
fseek(inputFile ,i*sizeof(double),SEEK_END);
while(( fread(&temp,sizeof(double),1,inputFile)==1 )) {
printf(" %lf \n",temp);
}
the program doesn't crash but it shows a one wrong value of temp
0.000000
any idea what I'm doing wrong here?