aboutsummaryrefslogblamecommitdiff
path: root/6.4/getch.c
blob: f271434b8a602da1f28ae5720958f99e3be2b9f1 (plain) (tree)






















                                                      
#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");
}