из файла массив 2мерный, сортируем строку с номером максимума(для каждой строки). Сортировка по убыванию

 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
int main() {
FILE *in, *ou;
if ((in = fopen("data.dat", "r")) == NULL) {
printf("Error open file\n");
return -1;
}
if ((ou = fopen("data.res", "w")) == NULL) {
printf("Error create file\n");
return -1;
}
double **mas;
int *sizeMas;
int buf, count = 0;
for (count = 1; !feof(in); count++) {
printf("fdfa\n");
sizeMas = (int*)realloc(sizeMas, count*sizeof(int));
int buff;
if (fscanf(in, "%d", &buff) != 1) {
printf("dsjflkd %d dsjkgn\n", buff);
break;
}
sizeMas[count-1] = buff;
char tt;
fscanf(in, "%c", &tt);
double **newMas = (double**)malloc(count*sizeof(double*));
for (int j = 0; j < count - 1; j++) {
newMas[j] = (double*)malloc(sizeMas[j]*sizeof(double));
for (int k = 0; k < sizeMas[j]; k++)
newMas[j][k] = mas[j][k];
}
mas = newMas;
mas[count-1] = (double*)malloc(sizeMas[count-1]*sizeof(double));
for (int i = 0; i < sizeMas[count-1]; i++)
fscanf(in, "%lf ", &mas[count-1][i]);
}
int max;
double maxx;
for (int i = 0; i < count - 1; i++) {
maxx = mas[i][0];
max = 0;
for (int j = 0; j < sizeMas[i]; j++)
if (mas[i][j] > maxx) {
maxx = mas[i][j];
max = j;
}
for (int j = 0; j < sizeMas[max]; j++)
for (int k = 0; k < sizeMas[max] - 1; k++)
if (mas[max][k] < mas[max][k+1]) {
int DUB = mas[max][k];
mas[max][k] = mas[max][k+1];
mas[max][k+1] = DUB;
}
}
for (int i = 0; i < count - 1; i++) {
for (int j = 0; j < sizeMas[i]; j++)
fprintf(ou, "%.3lf ", mas[i][j]);
fprintf(ou, "\n");
}
}