This is strange, my output to printf is exacty how i want it.
But the output to a file is not what I expected. My instructor for class is horrible. (long story)
the output to the regular printf is:
Temp Avg High Low
1173 46.00 100 -1
fprintf is :
(null)Temp/ Ave/ High/ Low
(null)1173/ 0.00/ -1 / 0 (the slashes aren't there, I added those to section off the categories and numbers)
I don't get why my file output is dorked up, can anyone point me in the write direction?
Thanks for any help. Yes I am new to programming.
my code is
Code:
#include<math.h>
#include<stdio.h>
#include<string.h>
#define inp_file "C:\\Users\\John\\Desktop\\ehhh\\temps.txt"
#define out_file "C:\\Users\\John\\Desktop\\ehhh\\averages.txt"
#define debug 1
int main(void) {
FILE *inp, *out;
double avg_temp;
int High, Low, temp;
inp = fopen(inp_file,"r");
out = fopen(out_file,"w");
if (debug) {
if (inp == NULL || out == NULL) {
printf("File does not exist\n");
return(0); } }
while (fscanf(inp,"%d\n", &temp) != EOF) {
printf("%d\n", temp);
}
High = 100; //highest temp
Low = -1; //lowest temp
avg_temp = 1173 / 25;
printf("Temp\t\tAve\t\tHigh\t\tLow\n");
printf("1173\t\t%.2f\t\t%d\t\t%d\n", avg_temp, High, Low);
fprintf(out,"%sTemp\t\tAve\t\tHigh\t\tLow\n");
fprintf(out,"%s1173\t\t%.2f\t\t%d\t\t%d", avg_temp, High, Low);
fclose(inp);
fclose(out);
return(0);
}