diff options
author | justanothercatgirl <sotov@twistea.su> | 2024-12-06 15:08:31 +0300 |
---|---|---|
committer | justanothercatgirl <sotov@twistea.su> | 2024-12-06 15:08:31 +0300 |
commit | a470c304199866aa1f3d39ff22ec30734f03d617 (patch) | |
tree | b08858e91b39fc108f2ab9b83c03ef7f881711ba /check.c | |
parent | 24b8430fa7a9a81b88c5c172c99bbc9a520ff4ba (diff) |
сделал 8 задание))))task8
Diffstat (limited to 'check.c')
-rw-r--r-- | check.c | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -0,0 +1,36 @@ +#include <stdio.h> +#include <stdlib.h> + +int main(int argc, char *argv[]) { + FILE ** files; + FILE * output; + size_t i; + double t, sum, tmp1, tmp2; + + if (argc < 3) return 1; + files = calloc(argc - 2, sizeof(FILE*)); + for (i = 1; i < argc - 1; ++i) { + if (!(files[i-1] = fopen(argv[i], "r"))) { + perror("opening files"); + return 1; + } + } + + output = fopen(argv[argc-1], "w+"); + for(;;) { + t = 0; + sum = 0; + for (i = 0; i < argc - 2; ++i) { + if (2 != fscanf(files[i], "%lf %lf", &tmp1, &tmp2)) goto end; + t += tmp1; + sum += tmp2; + } + t /= (argc-2); + fprintf(output, "%f %f\n", t, sum); + } +end: + fclose(output); + for (i = 0; i < argc - 2; ++i) fclose(files[i]); + free(files); + return 0; +} |