So I've read a lot of similar posts but I can't nail down what my issue is here.
{
FILE * fp;
fp = fopen("integer_store.txt", "r");
int total;
int i;
clock_t start, end;
double time;
start = clock();
fscanf(fp, "%d", &i);
while(!feof(fp)) {
fscanf(fp, "%d", &i);
total = total + i;
}
end = clock();
time = ((double)(end-start)) / CLOCKS_PER_SEC;
printf("Total: %d\n",total);
printf("Execution time: %f seconds \n",time);
fclose(fp);
}
The goal is to print a total of all the numbers in a file of ASCII numbers separated by spaces... everything seems to work except every time I run it i get a different total for the same file.