USING C CODING LANGUAGE Modify above code such that there ar

*USING C CODING LANGUAGE*

Modify above code such that there are now five components to it:

1. A function called foo that determines the size of the data file. It must be called 3 times by the main program, once for each input file (americanN.txt). The function must be defined as: int foo(char *filename) This code must be stored in a separate file called hw4-A-yourname.c.

2. A function called bar that writes the result to the output file (words.txt). It will be called once by the main program. The function must be defined as: void bar(char *filename, int total, char **words) This code must be stored in a separate file called hw4-B-yourname.c.

3. A main routine that calls foo and bar and handles the rest of the processing. This code must be stored in a separate file called hw4-yourname.c

4. A header/include that includes any and all header/include files required by the program. The header/include file may also include any global variables. This code must be stored in a separate file called hw4-yourname.h.

5. A script that has at least three lines. The first line will compile foo into a .o file. The second line will compile bar into a .o file. The third line will compile the main routine and link in both .o files resulting in an executable file called hw4.

You can use any editor to make the script. Then, at the Linux command line use chmod 755 script-name to make the script executable.

Solution

Ans .1. Struct stat finds the size of the file in C.

int foo(char* filename)
{
   struct stat st;

if (stat(filename, &st) == 0)
return st.st_size;

return -1;
}

Ans. 3.

*USING C CODING LANGUAGE* Modify above code such that there are now five components to it: 1. A function called foo that determines the size of the data file. I

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site