25 lines
736 B
C
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;
|
|
} |