#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) { int wordCount = 0; char lineRead[MAX_LINE_LEN]; while(fgets(lineRead, MAX_LINE_LEN, file) != NULL && wordCount < (int)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 = " ;,.\n"; char *token; 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(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; }