2025-10-30 16:35:43 +01:00

29 lines
836 B
C

#include "input.h"
#include <string.h>
#include <ctype.h>
#define MAX_WORD_LEN 100
// 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 anzahlWoerter = 0;
char zeile[500];
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
while(anzahlWoerter <= maxWordCount && fgets(zeile, sizeof(zeile), file)){
char *wort[] = strtok(zeile, ",; \n");
while(wort != NULL && anzahlWoerter <= maxWordCount){
strncpy(words[anzahlWoerter], wort, anzahlWoerter -1);
words[anzahlWoerter][MAX_WORD_LEN - 1]= '\0';
anzahlWoerter++;
*wort = strtok(NULL, ",; \n");
}
}
return anzahlWoerter;
}