Can anyone give me the code to make pelles C read numbers from a file, and then write to another file the average, high, and low temperatures, in that order.
Can anyone give me the code to make pelles C read numbers from a file, and then write to another file the average, high, and low temperatures, in that order.
I daresay yes. What have you tried?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
#include <stdlib.h>
#include<math.h>
#include<stdio.h>
#include<string.h>
#define inp_file "c:/code/temp/temps.txt"
#define out_file "c:/code/temp/averages.txt"
#define debug 1
int main(void) {
FILE *inp, *out;
double temp, average, high, low, input;
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(input,"%d",&temp) != EOF) {
printf("%s %lf\n",temp);
fprintf(out,"%s%lf\n",temp); }
fclose(inp);
fclose(out);
return(0);}
this is my code, but its not working and I cant quite figure out why.
Read this -> << !! Posting Code? Read this First !! >>
Then post your code again, this time using code tags to preserve some sense of indentation.
Though from editing your post, I see that it doesn't have any indentation to begin with.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
1) You expect temp to hold a double, yet your fscanf() is formatted to read int.
2) printf("%s %lf\n",temp); expects two parameters. Same with the next fprintf statement.