#include "input.h"
#include <string.h>
#include <ctype.h>

int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
    char line[MAX_LINE_LEN];
    unsigned int count = 0;

    if (file == NULL)
        return 0;

    // Zeile für Zeile lesen
    while (fgets(line, sizeof(line), file) != NULL && count < maxWordCount)
    {
        // Tokenisieren nach Leerzeichen, Komma, Semikolon, Tab, Newline
        char *token = strtok(line, " ,;\t\r\n");
        while (token != NULL && count < maxWordCount)
        {
            // In Großbuchstaben umwandeln und in Zielpuffer kopieren
            unsigned int i = 0;
            for (; i < MAX_WORD_LEN - 1 && token[i] != '\0'; i++)
            {
                words[count][i] = (char)toupper((unsigned char)token[i]);
            }
            words[count][i] = '\0';

            count++;
            token = strtok(NULL, " ,;\t\r\n");
        }
    }

    return (int)count;
}