diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c2550fb --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "files.associations": { + "input.h": "c" + } +} \ No newline at end of file diff --git a/Start_Windows/input.c b/Start_Windows/input.c index ed77805..b4ea2ec 100644 --- a/Start_Windows/input.c +++ b/Start_Windows/input.c @@ -8,5 +8,5 @@ // Read words from file and store in 'words' array int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount) { - + } \ No newline at end of file diff --git a/Start_Windows/test.c b/Start_Windows/test.c index 4e1d343..64b6f04 100644 --- a/Start_Windows/test.c +++ b/Start_Windows/test.c @@ -1,6 +1,40 @@ -#include - +#include "input.h" +#include +#include int main(){ - printf("Hello Patric \n"); - return 0; + // 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) + { + int zeilen = 0; + int spalten = 0; + file = fopen("words.txt", "r"); + if (file == NULL) + { + printf("Fehler beim öffnen der Wörter \n"); + return 1; + } + while(fgets(words[zeilen], MAX_WORD_LEN, file) != NULL) + { + int laenge = strlen(words[spalten]); + if (words[zeilen][laenge - 1] == '\n') + words[zeilen][laenge - 1] = '\0'; + spalten++; + zeilen++; + } + fclose(file); + + for (int i = 0; i < zeilen; i++) + { + for (int j = 0; j < spalten; j++) + { + printf("%c", words[i][j]); + } + } + printf("finished"); + return 0; + } + } \ No newline at end of file