diff options
author | Daniel <steew0x8@protonmail.com> | 2021-11-06 19:17:00 +0100 |
---|---|---|
committer | Daniel <steew0x8@protonmail.com> | 2021-11-06 19:17:00 +0100 |
commit | 7807b47e960f77aa780e2084641066da2f33f791 (patch) | |
tree | 257a54ce3aa3f2b1915cfef54d1352f4e69a2d4d /main.c | |
parent | 2dba790a5b0d1e61acee6da4b85a486b036446ba (diff) | |
download | rpncalc-7807b47e960f77aa780e2084641066da2f33f791.tar.gz |
added argument count check for funcs
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/main.c b/main.c index cb5dada..63e847f 100644 --- a/main.c +++ b/main.c @@ -6,6 +6,7 @@ #include <string.h> #include "cmds.h" #include <err.h> +#include <errno.h> #define BUF_SIZE 50 @@ -37,6 +38,10 @@ int main() { fgets(buf, BUF_SIZE, s.defbuf); buf[strcspn(buf, "\n")] = 0; double interpreted = strtod(buf, &endptr); + if (errno == ERANGE) { + fprintf(s.defout,"sorry, this number is too big\n"); + continue; + } if (interpreted == (double)0 && endptr == buf) { /* strtod returned the char it could not read */ TYPE t = discriminate(buf); if (t == OPERATOR ) { @@ -66,6 +71,7 @@ int main() { /* check for special commands, else pass to exec() */ if (strcmp(buf, "quit") == 0) { fprintf(s.defout, "quitting, bye!\n"); + free (s.sorted); exit(0); } else if (strcmp(buf, "list") == 0) { for (int i = 0; s.sorted[i].name != 0; i++) { |