getch.c
Get a character from the stdin, put it into a buffer (which has a size
of BUFSIZE).
#include <stdio.h>
#include "getch.h"
char buf[BUFSIZE];
int sp = 0;
int getch(void) {
return (sp > 0) ? buf[--sp] : getchar();
}
int fgetch(FILE *fp) {
return (sp > 0) ? buf[--sp] : getc(fp);
}
void ungetch(int c) {
if (sp >= BUFSIZE)
fprintf(stderr, "ERROR. ungetch: buffer is full.\n");
else
buf[sp++] = c;
}
Created: Nov 26, 1994
Last Revised: Dec 6, 1994
© Copyright 1994 Wei-Chang Shann
- Back to the home page of
Wei-Chang Shann.
- Connect to the home page of
Department of Mathematics, National Central University,
Taiwan.
shann@math.ncu.edu.tw