Question: The language is C and explanation with codes would be appreciated. You need to write a function called addFile(char * filename, int * sum) that

The language is C and explanation with codes would be appreciated.

You need to write a function called addFile(char * filename, int * sum) that opens a file named filename. If it fails, return false, and DO NOT fclose(). You have to read the integers in the file, and store the sum. Further instructions are in the comments in the function in file fileint.c.

You also need to write a function called writeSum(char * filename, int sum) that writes the sum as an integer which name is filename. Further instructions are in the comments in the function in file fileint.c

Required codes as follows:

// ***
// *** You MUST modify this file.
// ***
#include
#include
#ifdef TEST_ADDFILE
bool addFile(char * filename, int * sum)
{
// You cannot assume * sum is zero. Thus, * sum needs to be set 0
// open a file whose name is filename for reading
// if fopen fails, return false. Do NOT fclose
// if fopen succeeds, read integers using fscan (do not use fgetc)
//
// * sum stores the result of adding all numbers from the file
// When no more numbers can be read, fclose, return true
//
return true;
}
#endif
#ifdef TEST_WRITESUM
bool writeSum(char * filename, int sum)
{
// open a file whose name is filename for writing
// if fopen succeeds, write sum as an integer using fprintf
// fprintf should use one newline ' '
// fclose, return true
//
return true;
}
#endif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!