aboutsummaryrefslogblamecommitdiff
path: root/6.1.1/getch.c
blob: 2b86efed89c9dedb8bd56293d475f0db998f64d5 (plain) (tree)






















                                                       
#include <stdio.h>
#include <stdlib.h>
#include <error.h>
#include <errno.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
		error(EXIT_FAILURE, ENOBUFS , "getch");
}

char getch(void)
{
	return (top > 0) ? buff[--top] : getchar();
}