aboutsummaryrefslogtreecommitdiff
path: root/6.2/getch.c
diff options
context:
space:
mode:
authorsinanmohd <sinan@firemail.cc>2023-05-03 16:21:54 +0530
committersinanmohd <sinan@firemail.cc>2023-05-07 15:21:39 +0530
commit329fada630517195a472da703d19d7eced62c5a8 (patch)
tree8ef85bac36a3777e67fc10613ef9eaee8e46c59b /6.2/getch.c
parent16c2c412f3062924ad7869068730b2c56afbcff8 (diff)
6.2: initial commit
this version keeps the word count
Diffstat (limited to '6.2/getch.c')
-rw-r--r--6.2/getch.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/6.2/getch.c b/6.2/getch.c
new file mode 100644
index 0000000..2b86efe
--- /dev/null
+++ b/6.2/getch.c
@@ -0,0 +1,23 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <error.h>
+#include <errno.h>
+#include "getch.h"
+
+#define MAXBUFF 100
+
+char buff[MAXBUFF];
+static size_t top;
+
+void ungetch(char c)
+{
+ if (top < MAXBUFF)
+ buff[top++] = c;
+ else
+ error(EXIT_FAILURE, ENOBUFS , "getch");
+}
+
+char getch(void)
+{
+ return (top > 0) ? buff[--top] : getchar();
+}