/media/sda-magnetic/david/Dok-15-2023-11-27/informatik/bullshit-c/prognose-spastisch-2023-11/prognose.c


#include <stdio.h>

#define N       512
#define STRLEN  256

int main (int argc, char *argv []) {
    FILE *fp;
    FILE *fdes;
    int i, j;
    int n;
    char table [N][STRLEN];
    int score [N][N];
    int score2 [N];
    int max;
    int sum [N];
    if (argc != 2) {
        perror ("Can't open File");
        return -1;
    }
    if ((fp = fopen (argv [1], "r")) == NULL) {
        perror ("Can't open File");
        return -1;
    }

    if ((fdes = fopen ("scores.txt", "w")) == NULL) {
        perror ("Can't open File");
        return -1;
    }

    i = 0;
    while (!feof(fp)) {
        fgets (table [i], STRLEN, fp);
        i++;
    }
    n = i-1;

    for (i = 0;  i < n;  i++)
        printf ("%s\n", table [i]);

    for (i = 0;  i < n;  i++) {
        printf ("Wie wahrscheinlich ist? 0 .. 99, 0 sehr unwahrscheinlich - 99 sehr wahrscheinlich\n");
        printf ("%s\n", table [i]);
        scanf ("%i", &score2 [i]);
        //fprintf (fdes, "%2x", score2 [i]);
        for (j = 0;  j < n;  j++) {
            if (j == i)
                score [i][j] = 0;
            else {
                printf ("Wie wahrscheinlich ist? 0 .. 9, 0 sehr unwahrscheinlich - 9 sehr wahrscheinlich $$ ");
                printf ("%s $$ ", table [i]);
                printf ("%s ", table [j]);
                scanf ("%i", &score [i][j]);
                //fprintf (fdes, "%2x", score [i][j]);
            }
        }
        fprintf (fdes, "\n");
    }

    for (i = 100;  i >= 0;  i--) {
        for (j = 0;  j < n;  j++) {
            if (score2 [j] == i) {
                fprintf (fdes, "%i. %s\n", i, table [j]);
            }
        }
    }
    max = 0;
    for (i = 0;  i < n;  i++) {
        sum [i] = 0;
        for (j = 0;  j < n;  j++) {
            sum [i] += score [j][i];
        }
        if (sum [i] > max)
            max = sum [i];
    }
    for (max;  max >= 0;  max--) {
        for (j = 0;  j < n;  j++) {
            if (sum[j] == max)
                fprintf (fdes, "%i %s\n", sum [j], table [j]);
        }
    }
    fclose (fdes);
    fclose (fp);


}