i'm a newbie on c and i want to check if i have understood how funtions for file handling does work, here is my code. the issue that i faced is the evaluation of fx in every x is stored successfully on the file pointinterpol.dat, but when i want to read to stores its contents on the two array and print them, i got all elements of x,y arrays zero. I don't know what is going wrong ?
int main(void)
{
int i = 0;
float xe;
float x[8], y[8];
float fx = 1 / (1 + 25 * xe * xe);
FILE* fptr = NULL;
FILE* fread;
fptr = fopen("pointinterpol.dat", "w");
xe = -1;
while (i++ < 8)
{
fprintf(fptr, "%.3f %.3f\n", xe, 1 / (1 + 25 * xe * xe));
xe += 0.25;
}
i = 0;
fread = fopen("pointinterpol.dat", "r");
while (fscanf(fread, "%f %f", &x[i], &y[i]) == 2)
{
i++;
}
i = 0;
while (i < 8)
{
printf("\nx[%d] = %.2f *** y[%d] = %.2f\n", i, x[i], i, y[i]);
i++;
}
flcose(fptr);
fclose(fread);
return 0;
}