From 743795359c565ea59cd0f4f960075032c2b1b295 Mon Sep 17 00:00:00 2001 From: kugwa Date: Wed, 21 Oct 2015 15:39:27 +0800 Subject: Change the usage of fillTab() --- symbol-table.c | 17 +++++++++++++++-- symbol-table.h | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/symbol-table.c b/symbol-table.c index ca8dd3f..665c39c 100644 --- a/symbol-table.c +++ b/symbol-table.c @@ -83,9 +83,21 @@ void printSymTab(void) { } } -int fillTab(symtab **tp) { +symtab **fillTab(int *len) { int cnt = 0; for (int i = 0; i < TABLE_SIZE; i++) + { + symtab *symptr = hash_table[i]; + while (symptr != NULL) + { + cnt++; + symptr = symptr->front; + } + } + + symtab **tp = malloc(sizeof(symtab*)*cnt); + cnt = 0; + for (int i = 0; i < TABLE_SIZE; i++) { symtab *symptr = hash_table[i]; while (symptr != NULL) @@ -94,7 +106,8 @@ int fillTab(symtab **tp) { symptr = symptr->front; } } - return cnt; + *len = cnt; + return tp; } // vim: set sw=4 ts=4 sts=4 et: diff --git a/symbol-table.h b/symbol-table.h index c92986d..774b46c 100644 --- a/symbol-table.h +++ b/symbol-table.h @@ -10,6 +10,6 @@ typedef struct symtab symtab; symtab* lookup(char *name); void insertID(char *name); void printSymTab(void); -int fillTab(symtab **tp); +symtab **fillTab(int *len); // vim: set sw=4 ts=4 sts=4 et: -- cgit v1.2.3