include malloc include stdio include stdlib void min_max double arr in

  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
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
void min_max(double* arr, int str, int stl, double* min, double* max, double* sum)
{
*min = *(arr + stl * str + 0);
*max = *(arr + stl * str + 0);
*sum = 0;
for (int i = 0; i < stl-3; i++)
{
if (*min > *(arr + stl * str + i))
{
*min = *(arr + stl * str + i);
}
if (*max < * (arr + stl * str + i))
{
*max = *(arr + stl * str + i);
}
*sum += *(arr + stl * str + i);
}
}
int main(int argc, char* argv[])
{
setlocale(LC_ALL, "ru");
printf("all ok 0\n");
char path[250];
if (argc == 1)
{
printf("Enter file path:");
gets(path);
}
else
{
strcpy(path, path);
}
printf("all ok 0\n");
FILE* file = fopen(path, "r" );
printf("all ok open\n");
int N, M;
char c = '1';
M = N = 0;
printf("all ok 0\n");
while (!feof(file))
{
do
{
double tmp;
if (fscanf(file, "%lf", &tmp));
{
N++;
}
c = fgetc(file);
if (c == '\n')
{
M++;
}
} while (c == ' ');
}
double min, max, sum;
double* arr;
M++;
N/=M;
N += 3;
printf("all ok 1\n");
arr = calloc(N * M, sizeof(double));
rewind(file);
for (int i = 0; i < M; i++)
{
for (int j = 0; j < N - 3 ; j++)
{
fscanf(file, "%lf", (arr + i * N + j));
}
}
for (int i = 0; i < M; i++)
{
for (int j = 0; j < N; j++)
{
printf("%3.3lf ", *(arr + i * N + j));
}
printf("\n");
}
printf("all ok 2\n");
for (int i = 0; i < M; i++)
{
min_max(arr, i, N , &min, &max, &sum);
*(arr + i * N + (N - 3)) = sum;
*(arr + i * N + (N - 2)) = min;
*(arr + i * N + (N - 1)) = max;
for (int i = 0; i < M; i++)
{
for (int j = 0; j < N; j++)
{
printf("%3.3lf ", *(arr + i * N + j));
}
printf("\n");
}
}
fclose(file);
printf("all ok 3\n");
remove(path);
file = fopen(path, "w");
for (int i = 0; i < M; i++)
{
for (int j = 0; j < N; j++)
{
if (j == N - 1)
{
fprintf(file, "%3.3lf", *(arr + i * N + j));
}
else
{
fprintf(file, "%3.3lf ", *(arr + i * N + j));
}
}
fprintf(file, "\n");
}
printf("all ok 4\n");
fclose(file);
free(arr);
return 0;
}