summaryrefslogtreecommitdiffstats
path: root/4
diff options
context:
space:
mode:
Diffstat (limited to '4')
-rw-r--r--4/4.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/4/4.c b/4/4.c
index ccea5e8..ed443bf 100644
--- a/4/4.c
+++ b/4/4.c
@@ -28,6 +28,9 @@ double pop();
/* returns a value from stack without removing it */
double peek();
+/* clears the stack */
+void clear();
+
/* adds commands p (print top val without popping), c (duplicate top val), s
* (swap top two stack positions), d (clear stack) */
int main(int argc, char *argv[]) {
@@ -76,6 +79,9 @@ int main(int argc, char *argv[]) {
push(op2);
push(op1);
break;
+ case 'd':
+ clear();
+ break;
case '\n':
printf("\t%.8g\n", pop());
break;
@@ -112,6 +118,11 @@ double peek() {
}
}
+void clear() {
+ for (; sp > 0; sp--)
+ ;
+}
+
int getch() { return (bufp > 0) ? buf[--bufp] : getchar(); }
void ungetch(int c) {