1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
int count;
char filename[100], a[count], array[count], line, restofline1[count], restofline2[count];
double doub_i, doub_j;
FILE * newfile;
newfile = fopen(filename, "r+");
for (i=0; i<=count; i++)
{
fgets(&line, 100, newfile);
array[i] = line;
}
for (i=0; i<=count; i++)
{
for (int j=0; j<=count; j++)
{
sscanf(&array[i], "%f %s", &doub_i, &restofline1);
sscanf(&array[j], "%f %s", &doub_j, &restofline2);
if (doub_i > doub_j)
{
for (int b=0; b<=count; b++)
{
a[b] = array[i];
array[i] = array[j];
array[j] = a[b];
}
}
}
fputs(&array[i], newfile);
}
fclose(newfile);
return true;
}
else return false;
}
|