INPUT Update (denke fertig)
This commit is contained in:
parent
1a7ddaa7cd
commit
128a7f60a7
@ -8,5 +8,33 @@
|
|||||||
// Read words from file and store in 'words' array
|
// Read words from file and store in 'words' array
|
||||||
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
|
||||||
{
|
{
|
||||||
|
unsigned int count = 0;
|
||||||
|
char buffer[256]; // temporärer Speicher für Zeilen
|
||||||
|
|
||||||
|
// Solange Zeilen vorhanden sind
|
||||||
|
while (fgets(buffer, sizeof(buffer), file) != NULL)
|
||||||
|
{
|
||||||
|
char *token = strtok(buffer, " \t\r\n.,;:!?()[]{}\"'"); // Trennzeichen
|
||||||
|
|
||||||
|
while (token != NULL)
|
||||||
|
{
|
||||||
|
// Sicherheitscheck: Nicht über maxWordCount hinausgehen
|
||||||
|
if (count >= maxWordCount)
|
||||||
|
return count;
|
||||||
|
|
||||||
|
// Nur gültige Wörter übernehmen
|
||||||
|
// (z. B. alles in Kleinbuchstaben)
|
||||||
|
for (int i = 0; token[i]; i++)
|
||||||
|
token[i] = tolower((unsigned char)token[i]);
|
||||||
|
|
||||||
|
// In words[count] kopieren
|
||||||
|
strncpy(words[count], token, MAX_WORD_LEN - 1);
|
||||||
|
words[count][MAX_WORD_LEN - 1] = '\0'; // String terminieren
|
||||||
|
count++;
|
||||||
|
|
||||||
|
token = strtok(NULL, " \t\r\n.,;:!?()[]{}\"'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user