Menu

Need Functions Void Getints Char Argv Unsigned Int Inputone Unsigned Int Inputtwo Unsigned Q43884005

I need the functions voidget_ints(char** argv, unsignedint* input_one, unsignedint* input_two, unsignedlong int* output,int num_ints) and voidsave_output(char** argv, unsignedint* input_one, unsignedint* input_two, unsignedlong int* output,int num_ints).

The other functions are given for context.

In C please.

#include <stdlib.h> #include <stdio.h> #include main.h vou WNP /* Since the largest number is 4294967295, we need 11 charac/* This function takes in the two input file names (stored in argv) and determines the number of integers in each file. If th/* This function allocates engough memory to the three arrays to store num_ints elements each. This function should exit with/* This function reads in num_ints integers from the two input files and stores them in input_one (first input file) and inpu/* This function saves the summed output to an output file, whose name was specified with the program execution (i.e., argv[3/* This program takes in three text file names as input. The first two files contain N integers (where N >=0 and N <= 1,000,0

#include <stdlib.h> #include <stdio.h> #include “main.h” vou WNP /* Since the largest number is 4294967295, we need 11 characters (including the null character) to read a number from the file */ #define MAX NUM LENGTH 11 10 13 /* This function checks the number of input parameters to the program to make sure it is correct. If the number of input parameters is incorrect, it prints out a message on how to properly use the program. input parameters: int argc char** argv return parameters: none 15 16 17 18 void usage(int argc, char** argv), if(argc < 4) { fprintf(stderr, “usage: %s <input file 1> <input file 2> <output file>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 with EXIT_FAILURE. input parameters: char** argy 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) int n1 = 0; int n2 = 0; int temp; FILE * file1 = fopen(argv[1], “r”); // open files FILE * file2 = fopen(argv[2], “r”); if (file1 == NULL || file2 == NULL) { // if one or both of the files dont exist, exit exit(EXIT_FAILURE); while (fscanf(file1, “%d”, &temp) == 1) // check if an integer is in the file or not paten n1++; //if there is integer increment the ni (number of integers in file1) value while (fscanf(file2, “%d”, &temp) =1) // check if an integer is in the file or not, n2++; //if there is integer increment the n2 (number of integers in file2) value pulan fclose(file1); //close filel fclose(file2); //close file2 if (n1 == n2) //if both files have same number of integers return n1; else return -1; //if files have different count, /* This function allocates engough memory to the three arrays to store num_ints elements each. This function should exit with EXIT_FAILURE if the program fails to allocate 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, u nsigned long int** output, int num_ints), *input_one = (unsigned int*)malloc(num_ints * sizeof(MAX_NUM_LENGTH)); *input two = (unsigned int*) malloc(num ints * sizeof(MAX NUM LENGTH)); *output = (unsigned long int*)malloc(num_ints * sizeof(MAX_NUM_LENGTH)); if (input_one == NULL || input_two == NULL || output == NULL) { exit(EXIT_FAILURE); /* This function reads in num_ints integers from the two input files and stores them in input_one (first input file) and input_two (second input file). If one or both of the files do not exist, it should exit with EXIT_FAILURE. input parameters: char** argy 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), //open file // assign to input_one and input_two /* This function does an element-wise addition between the two input arrays (input_one and input_two) of size num_ints and stores the result in the 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) for(int i=0;i<num_ints; i++) output[i] = input one[i] + input_two[i]; /* 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 to how 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, unsigned int* 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 unsigned integers). The last file is the output file that this program should generate. 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 the input files. For example, if the two input files have eight integerse each input file 1 input file 2 output file NP COUP nnnnnn 10 1991 11231245 21235 1993 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 # of intsn”); 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(“%dn”, 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 . Show transcribed image text #include #include #include “main.h” vou WNP /* Since the largest number is 4294967295, we need 11 characters (including the null character) to read a number from the file */ #define MAX NUM LENGTH 11 10 13 /* This function checks the number of input parameters to the program to make sure it is correct. If the number of input parameters is incorrect, it prints out a message on how to properly use the program. input parameters: int argc char** argv return parameters: none 15 16 17 18 void usage(int argc, char** argv), if(argc

Expert Answer


Answer to I need the functions void get_ints(char** argv, unsigned int* input_one, unsigned int* input_two, unsigned long int* out…

OR