deleted testing lines -- tried to build main but had issues with graphicalGame.c

This commit is contained in:
pvtrx 2025-11-05 14:28:38 +01:00
parent 26efe137cb
commit c6664be88c
10 changed files with 97 additions and 23 deletions

View File

@ -2,17 +2,18 @@
"version": "0.2.0",
"configurations": [
{
"name": "Debug current C file",
"name": "Debug Word Salad",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"program": "${fileDirname}\\word-salad.exe",
"args": ["${fileDirname}/words.txt"],
"cwd": "${fileDirname}",
"stopAtEntry": false,
"cwd": "${fileDirname}",
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:/msys64/mingw64/bin/gdb.exe",
"preLaunchTask": "C/C++: gcc.exe build active file"
"preLaunchTask": "make"
}
]
}

View File

@ -1,5 +1,6 @@
{
"files.associations": {
"ctype.h": "c"
"ctype.h": "c",
"input.h": "c"
}
}

View File

@ -2,6 +2,22 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "make",
"type": "shell",
"command": "C:/msys64/usr/bin/make.exe",
"options": {
"cwd": "${fileDirname}",
"env": { "PATH": "C:/msys64/mingw64/bin;${env:PATH}" },
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
},
{
"label": "build C file",
"type": "shell",
@ -42,7 +58,7 @@
],
"group": {
"kind": "build",
"isDefault": true
"isDefault": false
},
"detail": "Task generated by Debugger."
}

View File

@ -6,5 +6,51 @@
// Read words from file and store in 'words' array
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount)
{
//TODO: Implement function to read words from file words.txt and store them in the words array. See, that in the file words are not seperated only by , ; or space but also by new lines.
int zeilen = 0;
if(file == 0)
{
printf("Fehler beim oeffnen der Woerter \n");
return -1;
}
while(fgets(words[zeilen], MAX_WORD_LEN, file) != 0) //auslesen der Zeilen
{
size_t laenge = strlen(words[zeilen]); // Datentyp size_t wird verwendet bei strlen
if(laenge > 0 && words[zeilen][laenge - 1] == '\n') //austauschen des Leerzeichens mit einem Nullzeichen falls nötig
{
words[zeilen][laenge - 1] = '\0';
laenge--; // Länge nach austauschen 1 kleiner weil nullzeichen nicht mitzählt
}
zeilen++;
}
int alt_zeilen = zeilen;
zeilen = 0;
char *teiler = " .,;\n\t\r";
char *woerter;
char aufgeteilt[MAX_NUMBER_OF_WORDS][MAX_LINE_LEN]; //zwischenspeicher fürs aufteilen der Wörter
for(int i = 0; i < alt_zeilen; i++) // Jede Zeile einzeln betrachten
{
woerter = strtok(words[i], teiler);
while(woerter != 0)
{
strncpy(aufgeteilt[zeilen], woerter, MAX_WORD_LEN); // Kopieren der aufgeteilten Wörter in den Zwischenspeicher
zeilen++;
woerter = strtok(NULL, teiler); // NULL sagt das man weiterhin in der selben Zeile bleibt und dort aufteilt
}
}
for(int i = 0; i < zeilen; i++)
{
strncpy(words[i], aufgeteilt[i], MAX_WORD_LEN); // überschreiben der Wörter zurück ins alte Array
size_t len = strlen(words[i]);
for(int j = 0; j < len; j++)
{
words[i][j] = toupper(words[i][j]); // groß schreiben
}
}
return zeilen;
}

View File

@ -5,6 +5,7 @@
#define MAX_WORD_LEN 100
#define MAX_LINE_LEN 1024
#define MAX_NUMBER_OF_WORDS 100
int readWords(FILE *file, char words[][MAX_WORD_LEN], unsigned int maxWordCount);

View File

@ -38,7 +38,7 @@ int main(int argc, char *argv[])
// Start game if all valid words were placed
if (placedWords == wordCount) {
startGame(wordSalad, SALAD_SIZE, words, wordCount);
startGame(wordSalad, SALAD_SIZE, words, wordCount, MAX_SEARCH_FIELD_LEN);
} else {
printf("Could not place all valid words. Placed %d out of %d words.\n", placedWords, wordCount);
}

View File

@ -1,10 +1,20 @@
CC = gcc
CFLAGS = -g -Wall
LDFLAGS = -lopengl32 -lgdi32 -lwinmm
BINARIES = ./windows
CC = C:/msys64/mingw64/bin/gcc.exe
CFLAGS = -g -Wall -I. -IC:/msys64/mingw64/include
LDFLAGS = -LC:/msys64/mingw64/lib -lraylib -lopengl32 -lgdi32 -lwinmm
raylibfolder = ./raylib
unityfolder = ./unity
SRC = main.c input.c game.c graphicalGame.c
OBJ = $(SRC:.c=.o)
EXE = word-salad.exe
all: $(EXE)
$(EXE): $(OBJ)
$(CC) -o $@ $(OBJ) $(LDFLAGS)
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
clean:
rm -f *.o *.exe
# --------------------------
# initiales Spiel bauen
@ -41,5 +51,4 @@ test: input.o game.o unit_tests.c
# --------------------------
# Clean
# --------------------------
clean:
del /f *.o *.exe