I suggest this:
All files you've open, should be closed after they've been processed. How do you know fclose() is not working?Code:
while((fscanf(tempsIn, "%lf", &nextVal)) != EOF) {
tempcount++;
total += nextVal;
}
Printable View
I suggest this:
All files you've open, should be closed after they've been processed. How do you know fclose() is not working?Code:
while((fscanf(tempsIn, "%lf", &nextVal)) != EOF) {
tempcount++;
total += nextVal;
}
i was using that code before, i already changed the format of my program, that won't work. i have added fclose to my program but that didn't change anything. come on im not asking anyone to write my code for me...i already wrote it. is there really no one that can help me??
sure when i use that form it does fix the problem of counting everything correctly, but it messes up everything else
i changed it but it still doesn't work can someone PLEASSEE!!! help me!!! i dont understnad what i am doing wrong
Code:#include <stdio.h>
#include <stdlib.h>
int main()
{
char inFileName[160];
int x;
int tempcount = 0;
int max = 0;
int min = 10000;
double sum = 0;
FILE *tempsIn;
printf("Temperature Analyzer v1.1\n");
printf("\n");
printf("What file to analyze?\n");
scanf("%s",&inFileName);
tempsIn = fopen("c:\\documents and settings\\christina kestler\\desktop\\temps.txt", "r");
if (inFileName == NULL) {
printf("File could not be opened.\n");
system("pause");
exit(EXIT_FAILURE);
}
while((fscanf(tempsIn, "%lf", &sum)) != EOF) {
tempcount++;
sum += x;
if(x > max)
max = x;
if(x < min)
min = x;
}
fclose(tempsIn);
double avg = (sum / tempcount);
printf("# of daily temps: %d\n", tempcount);
printf("Average daily temp: is %0.5lf\n", avg);
printf("Highest temp: %d\n", max);
printf("Lowest temp: %d\n", min);
system("PAUSE");
return 0;
}
i got it....looks like things were messed up with my file NOT my code....it was fine using feof!!!
Sympathies for your frustration. I just got back, and I'll take a look at it right now, and see what's up.
Stay around, if you can.
Well, never mind - and congrats.
Feof does work fine - sometimes.
The one I posted works fine - all the time.
thank you for being understanding, i am new at this and have been working on this code now for about 6 hours yesterday and about 5 now today...i was reaching my breaking point. thank you for your help!