#include "input.h" #include #include #include // 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 static int createSingleWords(char text[MAX_LINE_LEN], char words[][MAX_WORD_LEN], unsigned int maxWordCount); unsigned int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { unsigned int wordCount = 0; // Eingelesene Wörter char lineRead[MAX_LINE_LEN]; // Aktuell eingelesene Zeile while(fgets(lineRead, MAX_LINE_LEN, file) != NULL && wordCount < maxWordCount) { wordCount += createSingleWords(lineRead, words + wordCount, maxWordCount - wordCount); } return wordCount; //wordCount } static int createSingleWords(char text[MAX_LINE_LEN], char words[][MAX_WORD_LEN], unsigned int maxWordCount) { char *teiler = " ;,.\r\n"; char *token; unsigned int i = 0; token = strtok(text, teiler); while(token != NULL && i < maxWordCount) { strncpy(words[i], token, MAX_WORD_LEN - 1); //kleinbuchstaben --> GROßBUCHSTABEN int length = strlen(words[i]); for(unsigned int j = 0; j < length; j++) { if(islower(words[i][j])) { words[i][j] = toupper(words[i][j]); } } words[i][MAX_WORD_LEN - 1] = '\0'; token = strtok(NULL, teiler); i++; } return i; }