diff options
author | sinanmohd <sinan@firemail.cc> | 2023-04-22 17:46:20 +0530 |
---|---|---|
committer | sinanmohd <sinan@firemail.cc> | 2023-04-23 21:30:25 +0530 |
commit | 2f3d854c1226108907651a8fcf9228767eee9742 (patch) | |
tree | a5ba21f54083291fcc2fb57b5ff676d94883afee /5.20/getch.c | |
parent | c14dab7f3a1cf72619fadce9b81b55426dc0b32e (diff) |
5.20: initial commit
Diffstat (limited to '5.20/getch.c')
-rw-r--r-- | 5.20/getch.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/5.20/getch.c b/5.20/getch.c new file mode 100644 index 0000000..e41671e --- /dev/null +++ b/5.20/getch.c @@ -0,0 +1,22 @@ +#include <stdlib.h> +#include <stdio.h> +#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(); +} |