#include <stdio.h>
#include <string.h>

typedef struct {
    char naam[80];
    int punten;
} Deelnemer;

typedef struct {
    Deelnemer speler[100];
    int aantalSpelers;
} Stand; 

int main(void) {
    Stand leesData(void);
    void printWinnaars(Stand);
    Stand s;
    
    s = leesData();
    printWinnaars(s);
    
    fflush(stdin);
    getchar();
    return 0;
}

void printWinnaars(Stand st) {
    if (st.aantalSpelers == 0) {
        printf("Er is geen winnaar.\n");
    }
    else {
        int i, max;
        max = st.speler[0].punten;
        for (i = 1; i < st.aantalSpelers; i++) {
            if (st.speler[i].punten > max) {
                max = st.speler[i].punten;
            }
        }
        printf("De winnaar(s) is(zijn):\n");
        for (i = 0; i < st.aantalSpelers; i++) {
            if (st.speler[i].punten == max) {
                printf("%s\n", st.speler[i].naam);
            }
        }
    }
}       

Stand leesData(void) {
    Stand st;
    FILE* infile;
    infile = fopen("stand.txt", "r");
    if (infile == NULL) {
        printf("File stand.txt kan niet gelezen worden.\n");
        st.aantalSpelers = 0;
    } 
    else {
        int i = 0;
        char naam[80];
        int punten;
        while (i < 100 && fscanf(infile, "%79s%d", naam, &punten) == 2) {
            strcpy(st.speler[i].naam, naam);
            st.speler[i].punten = punten;
            i++;
        }
        st.aantalSpelers = i;
        fclose(infile);
    }
    return st;
}
