From 67a9c398322b4fa27e63e79f37966fe3ee3f780d Mon Sep 17 00:00:00 2001 From: GDBWNV <93523315+GDBWNV@users.noreply.github.com> Date: Tue, 4 Jun 2024 14:02:09 +0100 Subject: [PATCH] Symbol basic functionality. --- src/symboltable.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/symboltable.c b/src/symboltable.c index 38a0f7d..fb448c1 100644 --- a/src/symboltable.c +++ b/src/symboltable.c @@ -1,4 +1,4 @@ - +#include typedef struct st st; @@ -23,12 +23,21 @@ void st_add(st table, void* key, void* value) { table.tail = &n; } +// returns the pointer to key of the specified node, or null, if it does not exist void* st_search(st table, void* key) { return nodeSearch(table.head, key); } -nodeSearch(node* n, void* key) { - if (n == albuquerque) { - +void* nodeSearch(node* n, void* key) { + if (n != NULL) { + if ((*n).key == key) { + return (*n).value; + } + else { + return nodeSearch((*n).next, key); + } + } + else { + return NULL; } } \ No newline at end of file