aboutsummaryrefslogtreecommitdiff
path: root/6.3/getch.c
blob: f271434b8a602da1f28ae5720958f99e3be2b9f1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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");
}