4 Commits
Author SHA1 Message Date
ChristophFischer b9fd1b3553 input.c mit makefile getestet 2026-10-14 15:35:51 +02:00
ChristophFischer 86bf0775f8 neue makefile 2026-10-14 14:58:10 +02:00
fischerch103508 30c53ce8b9 input.c errors behoben 2026-10-13 20:33:40 +02:00
fischerch103508 61c60ebffd input angepasst 2026-10-13 19:45:13 +02:00
3 changed files with 27 additions and 21 deletions

No files matched your search

+15 -17
View File
@@ -8,27 +8,25 @@
// Read words from file and store in 'words' array // 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 puffer[MAX_LINE_LEN]; char puffer[MAX_WORD_LEN];
char *teiler = " ,;\n"; char *teiler = " ,;";
char *token; char *token;
FILE *words_txt_speicherort; //Zeiger auf den Speicherort der word.txt Datei unsigned int wordCount = 0;
words_txt_speicherort = fopen("words.txt","r"); //word.txt öffnen fgets(puffer, MAX_LINE_LEN, file);
if(words_txt_speicherort == NULL) //Abbruch falls words.txt nicht existieren würde token = strtok(puffer, teiler);
while(token != NULL && wordCount < maxWordCount)
{ {
return -1; strncpy(words[wordCount], token, MAX_WORD_LEN -1);
words[wordCount][MAX_WORD_LEN - 1] = '\0';
wordCount++;
token =strtok(NULL, teiler);
} }
fgets(puffer, MAX_LINE_LEN, words_txt_speicherort); //speichert alle Zeichen der words.txt datei in den speicher return wordCount;
token = strtok(puffer, teiler); //Trennt das erste Wort der Zeichenkette, abhängig von den Teilerbedingungen
while(token != NULL)
words = token; //speichert nur das einzelne Word in das words array; Problem: Laufindex der global gespeichert werden müsste; wie springe ich beim 2ten Funktionsaufruf zum nächsten Wort
int fclose(words_txt_speicherort);
} }
+5 -4
View File
@@ -36,10 +36,11 @@ int main(int argc, char *argv[])
// Create the word salad by placing words into grid // Create the word salad by placing words into grid
placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount); placedWords = createWordSalad(wordSalad, SALAD_SIZE, words, wordCount);
// TODO:
// Check if all words were successfully placed if(placedWords == wordCount)
// Start the game if successful {
// error message if some words couldn't be placed startGame(wordSalad, SALAD_SIZE, words, wordCount, 800);
}
} }
else else
+7
View File
@@ -25,6 +25,13 @@ wordsalad_initial:
# -------------------------- # --------------------------
# Normales Spiel bauen # Normales Spiel bauen
# -------------------------- # --------------------------
wordsalad_myversion: input.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a
$(CC) $(CFLAGS) -o wordsalad_myversion input.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
wordsalad_2: main.o input.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a
$(CC) $(CFLAGS) -o wordsalad_2 main.o input.o $(BINARIES)/libwordsalad_complete.a $(BINARIES)/libraylib.a $(LDFLAGS)
wordsalad: main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a wordsalad: main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a
$(CC) $(CFLAGS) -o wordsalad main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a $(LDFLAGS) $(CC) $(CFLAGS) -o wordsalad main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a $(LDFLAGS)