2025-11-02 17:09:44 +01:00

45 lines
1.4 KiB
C

//erstellt von Harun Faizi am 01.11.2025
#include "input.h"
#include <string.h>
#include <ctype.h> // Wichtig für toupper()
#include <stdio.h>
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
if (file == NULL)
return 0; // Sicherheitsprüfung, also wurde ein File gefunden
char line[MAX_LINE_LEN]; // Puffer für eine Zeile aus Datei
unsigned int wordCount = 0; // zählt die gefundenen Wörter
// Lese Datei Zeile für Zeile
while(fgets(line, sizeof(line), file) != NULL)
{
// Zerlege die Zeile in Wörter anhand der Trennzeichen
char *token = strtok(line, ".,; \t\n");
while (token != NULL && wordCount < maxWordCount)
{
// Kopiere das aktuelle Token ins Array und sichere Nullterminierung
strncpy(words[wordCount], token, MAX_WORD_LEN - 1);
words[wordCount][MAX_WORD_LEN - 1] = '\0';
// --- HINZUGEFÜGT ---
// Wandle das gesamte Wort in Großbuchstaben um
for(int i = 0; words[wordCount][i] != '\0'; i++)
{
words[wordCount][i] = toupper(words[wordCount][i]);
}
// --- ENDE HINZUGEFÜGT ---
wordCount++;
token = strtok(NULL, ".,; \t\n"); // nächstes Token
}
if (wordCount >= maxWordCount)
break;
}
return wordCount;
}