* Writes all valid tempertures readings and AC status to an output file specifie
ID: 3562179 • 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
At the moment my code looks similar (the below was quickly made up as an example) to;
Is there a way to only state fprintf once at the start then have the text followed by the variables at the end? Maybe a bit like;
I've searched the help files and looked into sprintf but I couldn't see anything that does this so thought I'd see if I'm wasting my time searching!
The help is much appreciated, and apologise if I've missed something staring me in the face in the help files!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.