2025-11-11 14:27:19 +01:00

33 lines
1.0 KiB
C

#include "input.h"
#include <string.h>
#include <ctype.h>
// TODO:
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
char zeile[MAX_LINE_LEN];
int anzahlWord = 0;
while (fgets(zeile, MAX_LINE_LEN, file)) {
char *teiler = " .,;";
char *token = strtok(zeile, teiler);
while (token != NULL && anzahlWord < maxWordCount) {
strncpy(words[anzahlWord], token, MAX_WORD_LEN - 1);
words[anzahlWord][MAX_WORD_LEN - 1] = '\0';
anzahlWord++;
token = strtok(NULL, teiler);
}
}
/*Alle Buchstaben zu Großbuchstaben umwandeln
*h
for (int i = 0; i < anzahlWord; i++) {
int laenge = strlen(words[i]);
for (int j = 0; j < laenge; j++)
words[i][j] = toupper(words[i][j]);
}
*/
return anzahlWord;
}