Files
I2-Pr/Wordsalat/input.c
T
2026-11-02 14:02:33 +01:00

25 lines
736 B
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)
{
unsigned int wordCount = 0;
char buffer[MAX_WORD_LEN];
while (wordCount < maxWordCount && fscanf(file, "%s", buffer) == 1) {
for (int i = 0; buffer[i]; i++) {
buffer[i] = tolower(buffer[i]);
}
strncpy(words[wordCount], buffer, MAX_WORD_LEN - 1);
words[wordCount][MAX_WORD_LEN - 1] = '\0';
wordCount++;
}
return wordCount;
}