diff --git a/Startcode/input.c b/Startcode/input.c index ed77805..e6b1dfe 100644 --- a/Startcode/input.c +++ b/Startcode/input.c @@ -6,7 +6,37 @@ // 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 readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount){ + + char lineRead[MAX_LINE_LEN] = {}; + char *splitters = ",; \n"; + int wordsRead = 0; + + while(fgets(lineRead,MAX_LINE_LEN,file) != NULL && wordsRead < maxWordCount){ + char *token = strtok(lineRead, splitters); + + while(token != NULL && wordsRead < maxWordCount){ + + strcpy(words[wordsRead],token); + //Kleinbuchstaben -> Grossbuchstaben + int len = strlen(words[wordsRead]); + for(int i = 0; i < len; i++){ //müsste einen kleinbustaben am ende haben + if(islower(words[wordsRead][i])){ + words[wordsRead][i] = toupper(words[wordsRead][i]); + } + } + + + wordsRead++; + token = strtok(NULL, splitters); + } + } + return wordsRead; +} + + + + + + -} \ No newline at end of file diff --git a/Startcode/makefile b/Startcode/makefile index 7cf1d4c..4613436 100644 --- a/Startcode/makefile +++ b/Startcode/makefile @@ -22,6 +22,15 @@ codefolder = . wordsalad_initial: $(CC) -o wordsalad_initial -L. $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS) +#-------------- +# Mein Test +#-------------- + +my_wordsalad_input: input.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a + $(CC) $(CFLAGS) -o my_wordsalad_input input.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS) + + + # -------------------------- # Normales Spiel bauen # --------------------------