From 53f4716354b2394154c0cc963e176344b1f61aaf Mon Sep 17 00:00:00 2001 From: Tobias Grampp Date: Thu, 4 Dec 2025 16:54:33 +0100 Subject: [PATCH] less, but still some problems with socre saving --- bintree.c | 11 ++++------- highscore.c | 3 +-- highscores.txt | 12 ++++++++++-- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/bintree.c b/bintree.c index ca4ae56..7168818 100644 --- a/bintree.c +++ b/bintree.c @@ -15,28 +15,25 @@ StackNode *stackRoot = NULL;//Generates a new, empty stack for next tree data // if isDuplicate is NULL, otherwise ignores duplicates and sets isDuplicate to 1 (or to 0 if a new entry is added). TreeNode *addToTree(TreeNode *root, const void *data, size_t dataSize, CompareFctType compareFct, int *isDuplicate) { - printf("Sind in add to tree. Root ist: %d\n", root); if(!root) { //root = malloc(sizeof(TreeNode)); - printf("NULL detected\n"); TreeNode *newNode = malloc(sizeof(TreeNode)); - printf("Node Allocated\n"); newNode->data = malloc(dataSize); - printf("data allcoated\n"); + newNode->left = NULL; + newNode->right = NULL; strcpy(newNode->data, data); - printf("data pasted\n"); if(isDuplicate) *isDuplicate = 0; return newNode; } if(compareFct(data, root->data) > 0) { - root->right = addToTree(root->right, data, dataSize, compareFct, isDuplicate); + root->right = addToTree((root->right), data, dataSize, compareFct, isDuplicate); } else if(compareFct(data, root->data) < 0) { - root->left = addToTree(root->left, data, dataSize, compareFct, isDuplicate); + root->left = addToTree((root->left), data, dataSize, compareFct, isDuplicate); } else { diff --git a/highscore.c b/highscore.c index 273ebb4..90199a0 100644 --- a/highscore.c +++ b/highscore.c @@ -52,6 +52,7 @@ static int calculateScore(double timeInSeconds, unsigned int len) // Load highscores from file into memory. void loadHighscores(const char *path) { + printf("pointer ist: %x", highscoreTree); FILE *file = fopen(path, "r"); if(file != NULL) @@ -66,9 +67,7 @@ void loadHighscores(const char *path) if(name != NULL && scoreStr != NULL) { HighscoreEntry entry = createHighscoreEntry(name, strtol(scoreStr, NULL, 10)); - printf("Pre Tree"); highscoreTree = addToTree(highscoreTree, &entry, sizeof(entry), compareHighscoreEntries, NULL); - printf("Post Tree"); } } diff --git a/highscores.txt b/highscores.txt index 520fe3d..01e2d79 100644 --- a/highscores.txt +++ b/highscores.txt @@ -1,2 +1,10 @@ -Lukas;4985 -player1;3999 +Ðáhý;0 +Ðáhý;0 +Ðáhý;0 +Ðáhý;0 +Ðáhý;0 +Ðáhý;0 +Ðáhý;0 +Ðáhý;0 +Ðáhý;0 +Ðáhý;0