From c14dab7f3a1cf72619fadce9b81b55426dc0b32e Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Mon, 10 Apr 2023 07:45:35 +0530 Subject: 5.19: initial commit, make use of makefiles and split main into multiple files --- 5.19/getch.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 5.19/getch.c (limited to '5.19/getch.c') diff --git a/5.19/getch.c b/5.19/getch.c new file mode 100644 index 0000000..e41671e --- /dev/null +++ b/5.19/getch.c @@ -0,0 +1,22 @@ +#include +#include +#include "err.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 + err("buff: stack overflow"); +} + +char getch(void) +{ + return (top > 0) ? buff[--top] : getchar(); +} -- cgit v1.2.3