Hi guys, I've googled around the web for some time now trying to find why my EOF doesn't work.
I'm supposed to write a function, and I'm mostly curious to why EOF doesn't work.
The program reads in the text-file in a different function.
=================================================
Code:
int las_data(FILE *tsin, struct seriepost serie[])
{
int a = 0;
int i = -1;
int c = 1;
float tal;
int antal_tal = 0;
int antal_tal_totalt = 0;
int loop_continue = 1;
int n;
/*
Totnr = Sum of all numbers
outnr = How many numbers that are over or below 5% of 200
medel = average
*/
serie[20].totnr = 0;
fscanf(tsin, "%f", &tal);
while (tal != EOF && a != 20 && loop_continue == 1)
{
a++;
serie[a].totnr = 0;
serie[a].outnr = 0;
serie[a].medel = 0;
antal_tal++;
while (tal != 0.0)
{
//Write in the number
//Check if number is 0
serie[a].totnr = serie[a].totnr + tal;
if (tal > 231 || tal < 209)
{
serie[a].outnr = serie[a].outnr + 1;
}
fscanf(tsin, "%f", &tal);
//printf("Serie%d Tal: %.2f\n",a,tal);
antal_tal++;
//Go back to while loop
}
if (tal == 0.0)
{
//Count average etc
//Removes 0 from average
antal_tal = antal_tal - 1;
if (antal_tal == 0)
{
antal_tal = 2;
}
serie[a].medel = serie[a].totnr / (float)antal_tal;
antal_tal_totalt = antal_tal_totalt + antal_tal;
antal_tal = 0;
}
fscanf(tsin, "%f", &tal);
loop_continue = (int)tal;
if (loop_continue != EOF) // THIS IS WHERE IT ONLY RETURNS 0
{
loop_continue = 1;
}
else
{
loop_continue = 0;
}
//Jumps back to loop
}
while(c == 1) //Only for testing
{
scanf("%d", &c);
}
return a;
}
=================================================
I translated most of the comments in the program, the comments with //printf are just for testing.
It always goes to 20.