summaryrefslogtreecommitdiffstats
path: root/4/8.c
diff options
context:
space:
mode:
authorSadeep Madurange <smadurange@users.noreply.github.com>2021-12-12 16:54:41 +0800
committerSadeep Madurange <smadurange@users.noreply.github.com>2021-12-12 16:54:41 +0800
commit4c2a037165c21ac8fd1007824be72a2a8d61e74e (patch)
tree12729040a473f7d597664db610da67d927a5c23a /4/8.c
parent8943e228e20f892c73b1a9aa1a4f2d4ef7a36d86 (diff)
downloadk&r-exercises-4c2a037165c21ac8fd1007824be72a2a8d61e74e.tar.gz
4.8
Diffstat (limited to '4/8.c')
-rw-r--r--4/8.c28
1 files changed, 5 insertions, 23 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[]) {