diff --git a/Start_Windows/input.c b/Start_Windows/input.c index 23fe982..3d3c138 100644 --- a/Start_Windows/input.c +++ b/Start_Windows/input.c @@ -2,7 +2,7 @@ #include #include -#define MAX_BUFFER_LEN 256 +static char *buffer; // TODO? // eine Funktion implementieren, die ein einzelnes Wort aus einer Textdatei (words.txt) einliest und als C-String zurückgibt. @@ -10,29 +10,51 @@ // Read words from file and store in 'words' array int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { - char buffer[MAX_BUFFER_LEN]; - int count = 0; - char *teiler = ".,; !?\n"; + int i = 0; + int word = 0; + int wordChar = 0; + int firstLetter = 0; - if(file == NULL) + if (file == NULL) { - printf("Fehler beim Öffnen von words.txt!\n"); - return -1; + return 0; } + + fscanf(file, "%10s", buffer); - while(fgets(buffer, MAX_LINE_LEN, file)) + do { - const char *wort = strtok(buffer, teiler); - while(wort != NULL && count < maxWordCount) + if ((buffer[i] >= 'A') && (buffer[i] <= 'Z')) { - strncpy(words[count], wort, MAX_WORD_LEN-1); - words[count][MAX_WORD_LEN-1] = '\0'; - count++; - - wort = strtok(NULL, teiler); + if (!firstLetter) + { + firstLetter = 1; + } + + words[word][wordChar] = buffer[i]; + wordChar++; } - } + else if ((buffer[i] >= 'a') && (buffer[i] <= 'z')) + { + if (!firstLetter) + { + firstLetter = 1; + } - return count; + words[word][wordChar] = toupper(buffer[i]); + wordChar++; + } + else if (firstLetter) + { + words[word][wordChar] = '\0'; + word++; + wordChar = 0; + firstLetter = 0; + } + + i++; + } while ((i < MAX_LINE_LEN) && (word < maxWordCount)); + + return word+1; } diff --git a/Start_Windows/input.o b/Start_Windows/input.o index b55950a..5924bd1 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 fb300e5..b7d99f9 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 56b6441..d31a043 100644 Binary files a/Start_Windows/wordsalad_myversion.exe and b/Start_Windows/wordsalad_myversion.exe differ