it is crashing when allocation memory. This is hard;/
HERE IS THE PROGRAM::::
////////////////////////////////PROGRAM REQUIREMENTS///////////////
Write a program to input the number of readings of floating-point numbers that are to be input from the user (key board). Then input the floating-point values from the user.
Then sort the numbers using an array of pointers to the floating point numbers. Do not alter the order of the original array.
Output the elements of the array sorted in ascending order, in the original order, and in descending order
There is to be no subscript array notation i.e. no square brackets. Function main() may contain only declarations, function calls to your declared functions, and comments (calls to malloc/calloc must be in a function other than main()). You must use three functions in addition to main().
///////////////////////MAIN//////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
//Prototype Declarations
float* getData(int* num);
void printData (float** ptr, float* arr, int num);
void sortData(float **ptr, int num);
float** allocPtr(float* arr, int num);
////////////////////////////////Main//////////////////////////////////////////
int main (void)
{
//decs
float* arr;
float** ptr;
int num;
It looks like you are freeing the allocated memory too soon. In your getData() you allocate memory, then do this: free(arr); and then you attempt to write arr:
1 2 3 4 5
//input data
printf ("Enter the values: ");
for(i = 0; i < *num; i++)
scanf(" %f", (arr + i));
There are similar problems elsewhere.
You must not free memory until you are completely done with it (after sorting the values and printing the results).
Since your functions return the pointers you can use the returned values to free the memory at the end of the program.