ToDo 2D char Array

This commit is contained in:
Björn 2025-10-22 18:11:46 +02:00
parent 02b4cb3b9b
commit eb15c18771

View File

@ -13,6 +13,17 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
if (file == NULL) { if (file == NULL) {
printf("words,txt konnte nicht geoffnet werden"); printf("words,txt konnte nicht geoffnet werden");
} }
// ToDo 2D char Array um wörter zu speichern kommt hier hin // ToDo 2D char Array um wörter zu speichern kommt hier rein
char word[MAX_WORD_LEN];
unsigned int count = 0;
while (fscanf(textdokument, "%s", word) != EOF && count < maxWordCount) {
// Kopiere das gelesene Wort in das 2D-Array
strncpy(words[count], word, MAX_WORD_LEN - 1);
words[count][MAX_WORD_LEN - 1] = '\0'; // Sicherstellen, dass der String nullterminiert ist
count++;
}
fclose(textdokument);
return count;
} }