From 329fada630517195a472da703d19d7eced62c5a8 Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Wed, 3 May 2023 16:21:54 +0530 Subject: 6.2: initial commit this version keeps the word count --- 6.2/getch.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 6.2/getch.c (limited to '6.2/getch.c') 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 +#include +#include +#include +#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(); +} -- cgit v1.2.3