aboutsummaryrefslogtreecommitdiff
path: root/7.2/getch.c
diff options
context:
space:
mode:
Diffstat (limited to '7.2/getch.c')
-rw-r--r--7.2/getch.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/7.2/getch.c b/7.2/getch.c
new file mode 100644
index 0000000..a473190
--- /dev/null
+++ b/7.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
+
+int gtop;
+char buff[MAXBUFF];
+
+char getch(void)
+{
+ return (gtop > 0) ? buff[--gtop] : getchar();
+}
+
+void ungetch(char c)
+{
+ if (gtop < MAXBUFF)
+ buff[gtop++] = c;
+ else
+ error(EXIT_FAILURE, ENOBUFS, "getch");
+}