aboutsummaryrefslogtreecommitdiff
path: root/6.1.1/getch.c
diff options
context:
space:
mode:
Diffstat (limited to '6.1.1/getch.c')
-rw-r--r--6.1.1/getch.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/6.1.1/getch.c b/6.1.1/getch.c
new file mode 100644
index 0000000..2b86efe
--- /dev/null
+++ b/6.1.1/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();
+}