Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need the functions void get_ints( char ** argv, unsigned int * input_one, unsigned int * input_two, unsigned long int * output, int num_ints) and

I need the functions void get_ints(char** argv, unsigned int* input_one, unsigned int* input_two, unsigned long int* output, int num_ints) and void save_output(char** argv, unsigned int* input_one, unsigned int* input_two, unsigned long int* output, int num_ints).

The other functions are given for context.

In C please.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

#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 ", 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=0 and N

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

Step: 3

blur-text-image

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

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

Solve the following 1,4 3 2TT 5x- 1+ (15 x) dx 5X

Answered: 1 week ago

Question

Why do mergers and acquisitions have such an impact on employees?

Answered: 1 week ago

Question

2. Describe the functions of communication

Answered: 1 week ago