Include Include Include Mainh Define Maxnumlength 11 Void Usage Int Argc Char Argv Argc 4 Q43906188
#include <stdlib.h>
#include <stdio.h>
#include “main.h”
#define MAX_NUM_LENGTH 11
void usage(int argc, char** argv)
{
if(argc < 4) {
fprintf(stderr,
“usage: %s <input file 1> <input file 2> <outputfile>n”,
argv[0]);
exit(EXIT_FAILURE);
}
}
/* This function takes in the two input file names (stored in argv)and
determines the number of integers in each file.
If the two files both have N integers, return N, otherwise return-1.
If one or both of the files do not exist, it should exit withEXIT_FAILURE.
input parameters:
char** argv
return parameters:
-1 if the two input files have different number of integers
N if the two input files both have N integers
*/
int get_num_ints(char** argv)
{
}
/* This function allocates engough memory to the three arrays tostore
num_ints elements each.
This function should exit with EXIT_FAILURE if the program fails toallocate
the memory.
input parameters:
unsigned int* input_one
unsigned int* input_two
unsigned long int* output
int num_ints
return parameters:
none
*/
void allocate_mem(unsigned int** input_one, unsigned int**input_two,
unsigned long int** output, int num_ints)
{
}
/* This function reads in num_ints integers from the two inputfiles and
stores them in input_one (first input file) and input_two (secondinput
file).
If one or both of the files do not exist, it should exit withEXIT_FAILURE.
input parameters:
char** argv
unsigned int* input_one
unsigned int* input_two
int num_ints
return parameters:
none
*/
void get_ints(char** argv, unsigned int* input_one, unsigned int*input_two,
unsigned long int* output, int num_ints)
{
}
/* This function does an element-wise addition between the twoinput arrays
(input_one and input_two) of size num_ints and stores the result inthe
output array (output).
input parameters:
unsigned int* intput_one
unsigned int* intput_two
unsigned long int* output
int num_ints
return parameters:
none
*/
void sum_ints(unsigned int* input_one, unsigned int*input_two,
unsigned long int* output, int num_ints)
{
}
/* This function saves the summed output to an output file,whose name was
specified with the program execution (i.e., argv[3]).
The file should containe one integer value per line, similarly tohow the
input files were stored.
input parameters:
char** argv
unsigned int* intput_one
unsigned int* intput_two
unsigned long int* output
int num_ints
return parameters:
none
*/
void save_output(char** argv, unsigned int* input_one, unsignedint* input_two,
unsigned long int* output, int num_ints)
{
}
/* This program takes in three text file names as input.
The first two files contain N integers (where N >=0 and N <=1,000,000)
whose values range from 0 to 4294967295 (i.e., 32-bit unsignedintegers).
The last file is the output file that this program shouldgenerate.
For all three files, there should be one integer per line.
For each line in the two input files, read in the two integers,add them, and
then store the sum in the output file.
Repeat this process until all integers have been read from theinput files.
For example, if the two input files have eight integerseeach
input file 1 input file2 output file
——————————————————–
1 2 3
5 2 7
8 5 13
1 12 13
2 2 4
10 2 12
1991 2 1993
11231245 21235 11252480
*/
int main(int argc, char** argv)
{
usage(argc, argv);
// Check the number of integers in the input files
int num_ints = get_num_ints(argv);
if(num_ints == -1) {
fprintf(stderr, “ERR: The two input files have different # ofintsn”);
exit(EXIT_FAILURE);
} else {
fprintf(stdout, “The two input files have %d integersn”,num_ints);
}
unsigned int* input_one = NULL;
unsigned int* input_two = NULL;
unsigned long int* output = NULL;
// Allocate memory to store the integers
allocate_mem(&input_one, &input_two, &output,num_ints);
// Read the integers from the two input files
get_ints(argv, input_one, input_two, output, num_ints);
// Sum up the numbers
sum_ints(input_one, input_two, output, num_ints);
for(int i = 0; i < num_ints; i++) printf(“%ldn”,output[i]);
// Store the result in the output file
save_output(argv, input_one, input_two, output, num_ints);
free(input_one);
free(input_two);
free(output);
return 0;
}
Fill out the five empty functions above, please do notchange any given code, do not add more functions.
Expert Answer
Answer to #include #include #include “main.h” #define MAX_NUM_LENGTH 11 void usage(int argc, char** argv) { if(argc < 4) { fprintf...
OR