Program :
Code:
#include <stdlib.h>
#include <stdio.h>
int compare_doubles (const void *Y, const void *Z)
{
double y = *((double *)Y);
double z = *((double *)Z);
if (y > z)
{
return 1;
}
else
{
if (y < z)
{
return -1;
}
else
{
return 0;
}
}
}
int main ()
{
int j = 0, nRW;
printf("Enter #ROWs: ");
scanf("%d", &nROW);
FILE *iPr = fopen("in.txt", "r");
double *b;
b = malloc(sizeof(double) * nRW);
while (!feof(iPr))
{
fscanf(iPr, "%lf,", &b[j]);
printf("%lf\n", b[j]);
j++;
}
qsort((void *)b, nRW, sizeof(double), compare_doubles);
printf("after sorting:\n");
for(j = 0; j < nRW; j++)
{
printf("%f\n", b[j]);
}
return 0;
}
Bookmarks