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

#define MAX_WORD_LEN 100

void capitalletters(char *str) {
    while (*str) {
        *str = toupper((unsigned char)*str);
        str++;
    }
}

int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
    char buffer[1024]; // größerer Puffer für ganze Zeile
    unsigned int count_word = 0;

    while (count_word < maxWordCount && fgets(buffer, sizeof(buffer), file) != NULL)
    {
        // Zeilenumbruch entfernen
        buffer[strcspn(buffer, "\r\n")] = '\0';

        // Zerlege Zeile in Wörter anhand von Leerzeichen, Komma und Semikolon
        char *token = strtok(buffer, " ,;");

        while (token != NULL && count_word < maxWordCount)
        {
            capitalletters(token); // Großschreiben
            strncpy(words[count_word], token, MAX_WORD_LEN - 1);
            words[count_word][MAX_WORD_LEN - 1] = '\0'; // Nullterminierung
            count_word++;

            token = strtok(NULL, " ,;");
        }
    }

    return count_word;
}