Answered step by step
Verified Expert Solution
Question
1 Approved Answer
no given file, but it can be anything as long as the first element is an int specifying the size and the rest are float
no given file, but it can be anything as long as the first element is an int specifying the size and the rest are float
Implement a function that will allocate a float array to hold values read from a file: float * readFloatFileIntoArray (FILE *fptr, int *length) The first value in the file will be an integer specifying how many floats will follow. That integer will tell you how big your array needs to be. You'll allocate that array and then read and store each of the float values from the file into the array, which will be returned to the calling program. Okay, so what is the second parameter? Well, that's how we can tell the calling program how many elements there are in the returned array. QUESTION: Suppose malloc fails (always check!), how will the calling program know that? Next, change your implementation of the above function so that it doesn't use any square brackets. There's no good reason for doing that except to get more familiar and comfortable with pointers. Because the user i.e., the calling program) will eventually need to free the array, create a function that will not only do that but will also set the user's array variable to NULL so that s/he doesn't accidently reference memory that has been freed. HINT: The user will have to pass his/her array variable by reference to your functionStep 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