From 32f9d2c9655f69b91be44be709240d2a45703c20 Mon Sep 17 00:00:00 2001 From: Lukas Weber Date: Tue, 4 Nov 2025 20:27:48 +0100 Subject: [PATCH] Finished input.c, should be FINISHED --- Start_Windows/input.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/Start_Windows/input.c b/Start_Windows/input.c index 94b1846..340855f 100644 --- a/Start_Windows/input.c +++ b/Start_Windows/input.c @@ -1,22 +1,24 @@ #include "input.h" #include #include -void readWordsFromLine(char buffer[], int* wordCount,char words[][MAX_WORD_LEN], unsigned int maxWords) { +void readWordsFromLine(char buffer[], int* wordCount, char words[][MAX_WORD_LEN], unsigned int maxWords) { char *token; - char *teiler = " ,;"; - token = strtok(buffer, teiler); + char *word_seperator = " ,;"; + token = strtok(buffer, word_seperator); while (*wordCount < maxWords && token != NULL) { //condition for reading new words from buffer - if (strlen(token) <= MAX_WORD_LEN) { //checks if word fits into buffer - for (int i = 0; i < strlen(token); i++) { - if (token[i] == '\n') + if (strlen(token) <= MAX_WORD_LEN) { //checks if word fits into wordsalad grid + for (int i = 0; i < strlen(token); i++) { //writes words char by char into array, stops at '\n' + if (token[i] == '\n') { break; + } else if (token[i] >= 97 && token[i] <= 122) { //converts lower case to upper case + token[i] = token[i] - 32; + } words[*wordCount][i] = token[i]; } (*wordCount)++; } - printf("%s\n", token); - token = strtok(NULL, teiler); + token = strtok(NULL, word_seperator); } } @@ -29,11 +31,11 @@ void readWordsFromLine(char buffer[], int* wordCount,char words[][MAX_WORD_LEN], int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { char buffer[MAX_LINE_LEN]; // prepares a large enough buffer to read one line from the .txt-file - int* wordCount; - *wordCount = 0; + int readwords = 0; + int *wordCount = &readwords; while (*wordCount < maxWordCount && fgets(buffer, MAX_LINE_LEN, file) != NULL) { - readWordsFromLine(buffer, *wordCount, words, maxWordCount); + readWordsFromLine(buffer, wordCount, words, maxWordCount); } - - return 0; +printf("%d\n", readwords); + return *wordCount; }