diff options
author | Daniel <steew0x8@protonmail.com> | 2021-11-07 00:06:58 +0100 |
---|---|---|
committer | Daniel <steew0x8@protonmail.com> | 2021-11-07 00:06:58 +0100 |
commit | 65b783d28ec01e8ed4ee8de0ae3180f6850a5a5b (patch) | |
tree | 6f2f10ed496fb26c628ad43496c85437aecca6ba | |
parent | 87b3c38991df6587d6ee720ddbfd2f3eb78d926c (diff) | |
download | rpncalc-65b783d28ec01e8ed4ee8de0ae3180f6850a5a5b.tar.gz |
fix list and error without message
-rw-r--r-- | cmds.c | 1 | ||||
-rw-r--r-- | main.c | 4 | ||||
-rw-r--r-- | state.h | 1 |
3 files changed, 4 insertions, 2 deletions
diff --git a/cmds.c b/cmds.c index ec7efa6..07707df 100644 --- a/cmds.c +++ b/cmds.c @@ -55,6 +55,7 @@ int search(const void *s1, const void *s2) { void init_state(state *s) { int numel = sizeof(CMD_LIST)/sizeof(CMD_LIST[0]); qsort(&CMD_LIST, numel, sizeof(CMD_LIST[0]), compare); + s->numel = numel; s->sorted = CMD_LIST; } diff --git a/main.c b/main.c index 9484a5f..c369290 100644 --- a/main.c +++ b/main.c @@ -37,7 +37,7 @@ int main() { fprintf(s.defout, s.prompt, s.command_count, s.last_op); s.last_op = 0; char *endptr = NULL; - if (s.stk.count == STACK_SIZE) err(1, "exceeded stk size"); + if (s.stk.count == STACK_SIZE) errx(1, "exceeded stk size"); fgets(buf, BUF_SIZE, s.defbuf); buf[strcspn(buf, "\n")] = 0; double interpreted = strtod(buf, &endptr); @@ -77,7 +77,7 @@ int main() { free (s.sorted); exit(0); } else if (strcmp(buf, "list") == 0) { - for (int i = 0; s.sorted[i].name != 0; i++) { + for (int i = 0; i < s.numel; i++) { fprintf(s.defout, "[%s]\t->\t%s\n", s.sorted[i].name, s.sorted[i].description); continue; } diff --git a/state.h b/state.h index a9b1a7b..fc7a4e5 100644 --- a/state.h +++ b/state.h @@ -26,6 +26,7 @@ typedef struct { stack stk; /* btree elements */ command *sorted; /* sorted by function name */ + int numel; } state; #endif |