diff options
| author | hachem <im@hachem.wtf> | 2026-10-04 16:03:42 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-10-04 16:03:42 +0200 |
| commit | 52dab7fc85d877e80e3032f0afabae906adebad8 (patch) | |
| tree | b6d56299b839413bb77b1b8c8fa9f7a682124a05 /user/calc.c | |
| parent | a8a35a00a3c3c57cfbef2311d0348376c2e83208 (diff) | |
feat: fs tree and free list alloc
Diffstat (limited to 'user/calc.c')
| -rw-r--r-- | user/calc.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/user/calc.c b/user/calc.c index 2d0e3f8..cf5b1d2 100644 --- a/user/calc.c +++ b/user/calc.c @@ -23,6 +23,7 @@ void _start(void) int valid = 1; int saw_number = 0; int position = 0; + while (position < length) { char character = line[position]; @@ -31,11 +32,13 @@ void _start(void) position++; continue; } + if (is_digit(character)) { long value = 0; while (position < length && is_digit(line[position])) value = value * 10 + (line[position++] - '0'); + if (operator == '+') accumulator += value; else if (operator == '-') @@ -52,6 +55,7 @@ void _start(void) } accumulator = (operator == '/') ? accumulator / value : accumulator % value; } + saw_number = 1; } else if (character == '+' || character == '-' || character == '*' @@ -67,6 +71,7 @@ void _start(void) break; } } + if (valid && saw_number) { put("= "); @@ -74,5 +79,6 @@ void _start(void) put("\n"); } } + sys_exit(0); } |
