From f8deef43e107fd204cf56f70e7674800995f345c Mon Sep 17 00:00:00 2001 From: Mihaela Creciun Date: Wed, 21 Oct 2026 13:55:13 +0200 Subject: [PATCH] Worteinlesen mit strncpy angepasst --- Startcode/input.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Startcode/input.c b/Startcode/input.c index 271e2ec..9c197ab 100644 --- a/Startcode/input.c +++ b/Startcode/input.c @@ -13,16 +13,18 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) } unsigned int count = 0; + char currentWord[MAX_WORD_LEN]; size_t length = 0; int tooLong = 0; int ch; - + while (count < maxWordCount && (ch = fgetc(file)) != EOF) { if (ch == ',' || ch == ';' || isspace((unsigned char)ch)) { if (length > 0 && !tooLong) { - words[count][length] = '\0'; + currentWord[length] = '\0'; + strncpy(words[count], currentWord, MAX_WORD_LEN); count++; } @@ -32,8 +34,7 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) else if (!tooLong) { if (length < MAX_WORD_LEN - 1) { - words[count][length] = - (char)toupper((unsigned char)ch); + currentWord[length] = (char)toupper((unsigned char)ch); length++; } else { @@ -44,10 +45,11 @@ int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) } if (count < maxWordCount && length > 0 && !tooLong) { - words[count][length] = '\0'; + currentWord[length] = '\0'; + strncpy(words[count], currentWord, MAX_WORD_LEN); count++; } return (int)count; - + } \ No newline at end of file