diff --git a/Start_Windows/input.c b/Start_Windows/input.c index f887d73..dd57252 100644 --- a/Start_Windows/input.c +++ b/Start_Windows/input.c @@ -2,8 +2,6 @@ #include #include -static char *buffer; - // TODO: // eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt. @@ -27,20 +25,49 @@ char *readSingleWord(FILE *file) int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { int i = 0; - int numberOfReadWords = 0; + int firstLetter = 0; + int word = 0; + int wordChar = 0; char currentChar = 0; - + do { - fgetc(file + i); + currentChar = fgetc(file); + if ((currentChar >= 'A') && (currentChar <= 'Z')) + { + if (!firstLetter) + { + firstLetter = 1; + } + + words[word][wordChar] = currentChar; + wordChar++; + } + else if ((currentChar >= 'a') && (currentChar <= 'z')) + { + if (!firstLetter) + { + firstLetter = 1; + } + + words[word][wordChar] = toupper(currentChar); + wordChar++; + } + else if (firstLetter) + { + words[word][wordChar] = '\0'; + word++; + wordChar = 0; + firstLetter = 0; + } + i++; - } while (currentChar != EOF); + } while ((currentChar != EOF) && (word < maxWordCount)); + - - - return numberOfReadWords; + return word; } diff --git a/Start_Windows/input.o b/Start_Windows/input.o index b55950a..f3c4fb9 100644 Binary files a/Start_Windows/input.o and b/Start_Windows/input.o differ diff --git a/Start_Windows/runTests.exe b/Start_Windows/runTests.exe index f623a8d..5ce8e2f 100644 Binary files a/Start_Windows/runTests.exe and b/Start_Windows/runTests.exe differ diff --git a/Start_Windows/wordsalad_myversion.exe b/Start_Windows/wordsalad_myversion.exe index a799513..c5f9799 100644 Binary files a/Start_Windows/wordsalad_myversion.exe and b/Start_Windows/wordsalad_myversion.exe differ