From 4c2a037165c21ac8fd1007824be72a2a8d61e74e Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Sun, 12 Dec 2021 16:54:41 +0800 Subject: 4.8 --- 4/8.c | 28 +++++----------------------- 4/9.c | 2 +- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/4/8.c b/4/8.c index 355b29a..b81378e 100644 --- a/4/8.c +++ b/4/8.c @@ -155,31 +155,13 @@ void clear() { ; } -int pushb = 0; -int pushbval = 0; - -int getch() { - if (pushb) { - pushb = 0; - return pushbval; - } - return (bufp > 0) ? buf[--bufp] : getchar(); -} +int getch() { return (bufp > 0) ? buf[--bufp] : getchar(); } void ungetch(int c) { - pushbval = c; - pushb = 1; -} - -void ungets(char s[]) { - int len, i; - len = strlen(s); - if (bufp + len - 1 >= BUFSIZE) - printf("ungets: too many characters\n"); - else { - for (i = len; i >= 0; i--) - buf[bufp++] = s[i]; - } + if (bufp >= BUFSIZE) + printf("ungetch: too many characters\n"); + else + buf[bufp++] = c; } int getop(char s[]) { diff --git a/4/9.c b/4/9.c index 46b0b3f..355b29a 100644 --- a/4/9.c +++ b/4/9.c @@ -10,7 +10,7 @@ #define ASSIGNMENT '2' /* signal that a variable was found */ #define VARIABLE '3' /* signal that a variable was found */ #define MAXVAL 100 /* max depth of val and var stack */ -#define BUFSIZE 100 +#define BUFSIZE 1 #define VARCOUNT 52 /* supported variable count */ #define INDEX(x) (x <= 'Z' ? x - 'A' : x - 71) /* index of the variable */ -- cgit v1.2.3