Question
Write a C program that uses command line arguments to have the user input the command as follows at the prompt ($ signifies the prompt):
Write a C program that uses command line arguments to have the user input the command as follows at the prompt ($ signifies the prompt):
$ my_prog 4 input.txt output.txt
The first argument my_prog is the name of the executable, 4 is the number of floating point numbers in the file called input.txt (this is the third argument and can be any integer) and the 4th argument is the filename output.txt in which you will write the results.
The program is similar to what you did in the previous class exercise. Your program opens the file input.txt and reads the float numbers from it into an array. The size of the array is the second argument (4 as seen above or whatever you choose as long as you have that many numbers in the input file). So, your program will have to first dynamically allocate an array of this size and then read the numbers from the input file input.txt into this array. The program will then print the sum, average, product, smallest and largest in the same format as you did in the previous class exercise. The difference is that the output will be send to the output file output.txt and not to the console like you did in the previous class exercise. Please verify after you run your program that the output.txt is created with the correct output.
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