Objectives: 1) Learn to read and use command line arguments 2) Learn to dynamica
ID: 3768942 • Letter: O
Question
Objectives:
1) Learn to read and use command line arguments
2) Learn to dynamically allocate memory using malloc
3) Learn to read binary data from a file
Description
Write a C program (not C++) In this programming assignment you will write a program that reads binary data from a file. The first value in the file is an integer that indicates the number of floating point values remaining in the file. The remaining data is the actual floating point values. Your program must do the following:
1. The name of the input file is to be passed into the program as a command line argument.
2. The program will open this binary file, and read the first integer in the file. It will then dynamically create an array of floats of this size using the malloc function.
3. The program will then read the floating point values and store them into this newly created array.
4. Finally, the program will print out the floating point values in this array in reverse order, one value per line.
Files data1 and data2 are now on the course web site. The file data1 contains the following:
4, 1.1, 2.2, 3.3, 4.4
The output from your program ($./a.out data1 or $binread data1) should give
4.400000
3.300000
2.200000
1.100000
Explanation / Answer
#include <stdio.h>
#include <malloc.h>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.