From 078e7fcf44a45ceaa48c3139385f13245a34e188 Mon Sep 17 00:00:00 2001 From: Lukas Weber Date: Tue, 4 Nov 2025 00:19:45 +0100 Subject: [PATCH 1/3] Continued working on input.c, Version 1, still no testing for functionability --- .idea/.gitignore | 8 + .idea/editor.xml | 580 ++++++++++++++++++++++++++++++++++++++++++ .idea/vcs.xml | 6 + Start_Windows/input.c | 21 +- 4 files changed, 614 insertions(+), 1 deletion(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/editor.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/editor.xml b/.idea/editor.xml new file mode 100644 index 0000000..1f0ef49 --- /dev/null +++ b/.idea/editor.xml @@ -0,0 +1,580 @@ + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Start_Windows/input.c b/Start_Windows/input.c index 949ef93..4922fd9 100644 --- a/Start_Windows/input.c +++ b/Start_Windows/input.c @@ -4,8 +4,27 @@ // TODO: // eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt. - // Read words from file and store in 'words' array int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { + char buffer[101]; // prepares a large enough buffer to read one line from the .txt-file + char *wordseperator = " ,;"; // sets up checks for seperated words + char *token; + int readwords = 0; + + while (readwords < maxWordCount) { + + do { + token = strtok(buffer, wordseperator); + } while (*token == ' ' || *token == ',' || *token == ';'); + if (strlen(token) <= MAX_WORD_LEN) { + for (int i = 0; i < strlen(token); i++) { + words[readwords][i] = token[i]; + } + readwords++; + } + token = strtok(NULL, wordseperator); + } + + return 0; } From f036995e78f6f95756d71400a2aa571294a9bba0 Mon Sep 17 00:00:00 2001 From: Lukas Weber Date: Tue, 4 Nov 2025 19:54:04 +0100 Subject: [PATCH 2/3] Finished input.c V1, starting test and fix phase --- Start_Windows/input.c | 45 ++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/Start_Windows/input.c b/Start_Windows/input.c index 4922fd9..94b1846 100644 --- a/Start_Windows/input.c +++ b/Start_Windows/input.c @@ -1,30 +1,39 @@ #include "input.h" #include #include +void readWordsFromLine(char buffer[], int* wordCount,char words[][MAX_WORD_LEN], unsigned int maxWords) { + char *token; + char *teiler = " ,;"; + token = strtok(buffer, teiler); + + 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') + break; + words[*wordCount][i] = token[i]; + } + (*wordCount)++; + } + printf("%s\n", token); + token = strtok(NULL, teiler); + } + +} + + // TODO: // eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt. // Read words from file and store in 'words' array int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { - char buffer[101]; // prepares a large enough buffer to read one line from the .txt-file - char *wordseperator = " ,;"; // sets up checks for seperated words - char *token; - int readwords = 0; - - while (readwords < maxWordCount) { - - do { - token = strtok(buffer, wordseperator); - } while (*token == ' ' || *token == ',' || *token == ';'); - if (strlen(token) <= MAX_WORD_LEN) { - for (int i = 0; i < strlen(token); i++) { - words[readwords][i] = token[i]; - } - readwords++; - } - token = strtok(NULL, wordseperator); + char buffer[MAX_LINE_LEN]; // prepares a large enough buffer to read one line from the .txt-file + int* wordCount; + *wordCount = 0; + while (*wordCount < maxWordCount && fgets(buffer, MAX_LINE_LEN, file) != NULL) { + readWordsFromLine(buffer, *wordCount, words, maxWordCount); } - return 0; + return 0; } From 32f9d2c9655f69b91be44be709240d2a45703c20 Mon Sep 17 00:00:00 2001 From: Lukas Weber Date: Tue, 4 Nov 2025 20:27:48 +0100 Subject: [PATCH 3/3] 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; }