Testdatei läuft jezt
This commit is contained in:
commit
2998c1c261
@ -1,12 +1,39 @@
|
||||
#include "input.h"
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <stdio.h> //sicherstellen, dass FILE deklariert ist
|
||||
// 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)
|
||||
{
|
||||
unsigned int count = 0;
|
||||
char buffer[256]; // temporärer Speicher für Zeilen
|
||||
|
||||
// zusätzliche Bedingung "count < maxWordCount"
|
||||
while (count < maxWordCount && fgets(buffer, sizeof(buffer), file) != NULL)
|
||||
{
|
||||
// gleiche Trennzeichen, aber Formatierung beibehalten
|
||||
char *token = strtok(buffer, " \t\r\n.,;:!?()[]{}\"'"); // Trennzeichen
|
||||
|
||||
while (token != NULL)
|
||||
{
|
||||
if (count >= maxWordCount)
|
||||
break; // Sicherheitsabbruch auch hier
|
||||
|
||||
// toupper(), um Großbuchstaben zu erzwingen
|
||||
for (int i = 0; token[i]; i++)
|
||||
token[i] = toupper((unsigned char)token[i]);
|
||||
|
||||
// sicheres Kopieren ins Zielarray
|
||||
strncpy(words[count], token, MAX_WORD_LEN - 1);
|
||||
words[count][MAX_WORD_LEN - 1] = '\0'; // String terminieren
|
||||
count++;
|
||||
|
||||
token = strtok(NULL, " \t\r\n.,;:!?()[]{}\"'");
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
@ -19,6 +19,9 @@ wordsalad_initial:
|
||||
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)
|
||||
|
||||
wordsalad_myversion: main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a
|
||||
$(CC) $(CFLAGS) -o wordsalad_myversion main.o input.o game.o graphicalGame.o $(BINARIES)/libraylib.a $(LDFLAGS)
|
||||
|
||||
main.o: main.c
|
||||
$(CC) -c $(CFLAGS) main.c
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user