Question
File input/output c program use input1.txt & input2.txt Implement the following functions for the lab assignment. int loadNumbers(char*, int *,int): This function takes the input
File input/output c program
use input1.txt & input2.txt
Implement the following functions for the lab assignment.
int loadNumbers(char*, int *,int): This function takes the input file name, the integer pointer to the array and the count of numbers . It opens the input file, if unable to open it returns 0 otherwise it loads the numbers from the file to the integer pointer and returns 1 at the end.
void printNumbers(int*, int): This function prints the content of the array on to the screen, takes in the integer pointer and the size of the array.
float findAverage(int *, int): Takes in the integer pointer and find the average of all the numbers and returns it.
int findMax(int *,int): Takes in the integer pointer and the size and finds the maximum number in the array.
int findMin(int *, int): Takes in the integer pointer and the size and finds the maximum number in the array.
int writeData(char *,int*,int): Takes the output filename, integer pointer denoting the integers, and the size of the array. Open the output file in this function, write all the information which is on the screen also to the output file and return 1 at the end. If unable to open return 0 and exit out of the code. Call this function twice, once for each input file and each set of values. Refer the sample output.txt posted on blackboard.
int main(): Use command line arguments to read the file names and the length of records. Call loadNumbers function and load the inputs from the file into two integer pointers for which you need to malloc space. Print the numbers and then perform all the stats and print those values too.Then call the writeData function. See sample output below and the sample output.txt on blackboard and follow that.
Remember to free all the malloc-d memory correctly.
Note
Use of arrays is not allowed for the lab assignment instead start with an integer pointer and use malloc function to allocate only the required amount of memory.
Use POINTER NOTATION AND POINTER ARITHMETIC only to implement the assignment.
Sample Output
dpstm3:~$ ./a.out
USAGE ERROR : CHECK THE COMMAND LINE ARGUMENTS
dpstm3:~$ ./a.out input1.txt
USAGE ERROR : CHECK THE COMMAND LINE ARGUMENTS
dpstm3:~$ ./a.out 8 input1.txt input2.txt
USAGE ERROR : CHECK THE COMMAND LINE ARGUMENTS
dpstm3:~$ ./a.out 8 input1.txt input2.txt output1.txt output2.txt
The numbers in input1.txt are:
1 11 12 13 14 7 8 9
The mean of all the numbers = 9.38
The minimum of all the numbers = 1
The maximum of all the numbers = 14
Output written to the output file --->output1.txt
The numbers in input2.txt are:
9 8 7 6 5 4 3 2
The mean of all the numbers = 5.50
The minimum of all the numbers = 2
The maximum of all the numbers = 9
Output written to the output file --->output2.txt
**********************************************************************
I just need help writing the loadNumbers, printNumbers, and writeData functions
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started