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)
{
//declarations
[code] float* arr; [\code]
[code] float** ptr;[\code]
[code] int num;[\code]
//statements
[code] arr = getData(&num);[\code]
[code] ptr = allocPtr(arr, num);[\code]
[code] sortData(ptr, num);[\code]
[code] printData (ptr, arr, num);[\code]
return 0;
} // main
/* :::::::::::::::::::::::getData:::::::::::::::::::: :::::::
*/
float* getData(int* num)
{
//Local Declarations
[code] int i; [\code]
[code] float* arr;[\code]
//statements
[code] printf("Enter number of floats you wish to input: ");[\code]
[code] scanf ("%d", num); [\code]
//Allocate memory
[code] arr = (float*) calloc (*num, sizeof(float));[\code]
[code] if(arr == NULL)[\code]
[code] {printf("Out of memory"); exit(100);}
[code] free(arr);[\code]
//input data
[code] printf ("Enter the values: ");[\code]
[code] for(i = 0; i < *num; i++)[\code]
[code] scanf(" %f", (arr + i));[\code]
[code] return arr; [\code]
}//getdata
float** allocPtr(float* arr, int num)
{
//decs
[code] int i;[\code]
[code] float** ptr;[\code]
//statement
[code] ptr = (float**) calloc (num, sizeof(float*));[\code]
[code] if(ptr == NULL)[\code]
[code] {printf("Out of memory"); exit(100);}[\code]
[code] for (i = 0; i < num; i++)[\code]
[code] **(ptr + i) = *(arr + i);[\code]
[code] free(ptr);[\code]
[code] return ptr;[\code]
}//alocPtr
void printData (float** ptr, float* arr, int num)
{
//decs
[code] int i;[\code]
//statements
[code] printf ("The Array you entered is:\n");[\code]
[code] for(i = 0; i < num; i++)[\code]
[code] printf("\n\t%.2f\n", *(arr + i));[\code]
[code] printf("\n");[\code]
[code] printf ("Decending Order:\n");[\code]
[code] for(i = 0; i < num; i++)[\code]
[code] printf("\n\t%.2f\n", **(ptr + i));[\code]
[code] printf("\n");[\code]
[code] printf ("Ascending Order:\n");[\code]
[code] for(i = num - 1; i <= 0; i--)[\code]
[code] printf("\n\t%.2f\n", **(ptr + i));[\code]
[code] printf("\n");[\code]
[code] return;[\code]
}
void sortData(float **ptr, int num)
{
//decs
[code] float *temp;[\code]
[code] int i; [\code]
//statements
[code] for(i=0;i<(num-1);i++)[\code]
[code] {[\code]
[code] if(**(ptr + i + 1 ) < **(ptr + i))[\code]
[code] {[\code]
[code] temp = *(ptr + i);[\code]
[code] *(ptr + i) = *(ptr + i + 1);[\code]
[code] *(ptr + i + 1) = temp;[\code]
[code] }
}
return;
}