Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Web Database Development Step By Step

Authors: Jim Buyens

1st Edition

0735609667, 978-0735609662

More Books

Students also viewed these Databases questions