diff options
author | sinanmohd <sinan@firemail.cc> | 2023-05-08 16:59:02 +0530 |
---|---|---|
committer | sinanmohd <sinan@firemail.cc> | 2023-05-09 10:26:15 +0530 |
commit | 3f761f64d02480c81177e39af2f00f0e76b6f113 (patch) | |
tree | 5df4e643cce5e626fc00af16935616ea0df40927 /6.4/getch.c | |
parent | 2bc5c4c55b979af164c0bf7539e4f0bae6c263e8 (diff) |
6.4: initial comiit
Diffstat (limited to '6.4/getch.c')
-rw-r--r-- | 6.4/getch.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/6.4/getch.c b/6.4/getch.c new file mode 100644 index 0000000..f271434 --- /dev/null +++ b/6.4/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 top; +char buff[MAXBUFF]; + +char getch(void) +{ + return (top > 0) ? buff[--top] : getchar(); +} + +void ungetch(char c) +{ + if (top < MAXBUFF) + buff[top++] = c; + else + error(EXIT_FAILURE, ENOBUFS, "getch"); +} |