feat: Logik in input.c implementiert

This commit is contained in:
Mapama committed 2026-10-26 08:20:48 +01:00
1 parent 93db739464
commit f4e920ce5b
1 file changed
+20
+20
View File
@@ -8,5 +8,25 @@
// Read words from file and store in 'words' array // Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{ {
if (file == NULL) {
return 0;
}
char line[MAX_LINE_LEN];
unsigned int count = 0;
while (fgets(line, sizeof(line), file) != NULL && count < maxWordCount) {
char *token = strtok(line, " ,;\n\r\t");
while (token != NULL & count < maxWordCount) {
if (strlen(token) > 0) {
strncpy(words[count], token, MAX_WORD_LEN - 1);
words[count][MAX_WORD_LEN - 1] = '\0';
for (int i= 0; words[count][i] != '\0'; i++) {
words[count][i] = toupper((unsigned char)words[count][i]);
}
count++;
}
token = strtok(NULL, " ,;\n\r\t");
}
}
return count;
} }