Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

* Writes all valid tempertures readings and AC status to an output file specifie

ID: 3562178 • Letter: #

Question

* Writes all valid tempertures readings and AC status to an output file specified by fileName * using the format: * * HH:MM TT.TTT AC * * HH:MM reports the time at which the temperature was recorded specified in 24 hour format. * * TT.TTT represents the filtered temperature value in Fahrenheit as a floating point value with * three decimal digits of precision. * * AC reports the determined status of the air conditioner, where a 0 represents the the AC * was Off and a 1 represents the AC was On. * * Each entry is separated by a single tab character ( ). * * Retruns false if the specified file could not be written to, and true otherwise. *8 */

bool WriteTempDataToFile(ACTempData acTemps[], char *fileName) {

int i=0;

FILE* outFile = NULL; // File pointer

// Open file

outFile = fopen(fileName, "w");

if( outFile == NULL ) {

printf("Could not open file myoutfile.txt. ");

return -1; // -1 indicates error }

// Write to file

for(i=0;i< MinPerDay;i++){

fprintf(??); }

// Done with file, so close it

fclose(outFile);

return true;

}

I'm confused at what should be in my fprintf statement?

Explanation / Answer

Any time you print information, you should make sure it is of interest to the user of the program every time the code is run.. For example a function that compute pi should never use fprintf. Instead, such a function should return the value of pi for use by other parts of the program. If this approximated value of pi is of interest to the user, then the main program can print the result.

Proper use of fprintf to display the result of a function

Improper use of fprintf to display the result of a function

Notice how the second example prints "the sum is XX" every time the add function is called. In a program that adds millions of numbers, this would become quite annoying very quickly.