#include "input.h" #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 int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { /*file = fopen("words.txt", "r"); //liest das doc ein if (file == NULL) return -1;*/ FILE *ptr; char text [2000]; char line[200]; char value; int i = 0; int start = 0, end= 0; ptr = fopen("words.txt", "r"); if (ptr == NULL) { printf("Datei konnte nicht geöffnet werden.\n"); return 1; } while (fgets(line, sizeof(line), ptr)) { for (int j = 0; line[j] != '\0'&& i < sizeof(text)-1;j++) { text[i++] = line[j]; } } text[i] = '\0'; fclose(ptr); printf("%s\n", text); //sortierung der wörter in words(unterhalb) const char *trenner = ",; \n"; token = strtok(text, trenner); while (token != NULL) { strncpy(words[zaehler], token, MAX_WORD_LEN - 1); words[zaehler][MAX_WORD_LEN - 1] = '\0'; token = strtok(NULL, trenner); zaehler++; } //alle buchstaben in großbuchstaben ändern for (int h = 0; h < zaehler; h++) { for (int check = 0; words[h][check] != '\0'; check++) { if (words[h][check] >= 'a' && words[h][check] <= 'z') { words[h][check] -= 32; // direkt ins Array schreiben } } } return 0; }