implemented input.c (fails unit test, wegen Groß/Kleinschreibung) und game.c tests sind jetzt ok

This commit is contained in:
sengpielto106561 committed 2026-10-26 17:22:23 +01:00
1 parent ce4be9f902
commit 029eb426ab
2 files changed
+32 -15

No files matched your search

+25
View File
@@ -1,6 +1,7 @@
#include "input.h"
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
// TODO:
// eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt.
@@ -8,5 +9,29 @@
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
int count = 0;
char *line = calloc(MAX_LINE_LEN, sizeof(char));
char delimit[] = ",.;:!? \n";
while(fgets(line, MAX_LINE_LEN, file) != NULL && (count < maxWordCount)){
char *token = strtok(line, delimit);
while(token != NULL){
size_t len = strlen(token);
token[len] = '\0';
char copy[MAX_LINE_LEN];
strncpy(copy, token, len);
copy[len] = '\0';
strncpy(words[count], copy, len);
words[count][len] = '\0';
count++;
token = strtok(NULL, delimit);
}
}
return count;
}