home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programming
/
powerprogramming1994.iso
/
progtool
/
microcrn
/
issue_40.arc
/
DAIMS.ARC
/
CHBUFFER.CPP
< prev
next >
Wrap
Text File
|
1988-02-10
|
896b
|
51 lines
#include "chbuffer.hxx"
#undef TEST
/*
-*++ char_buffer::put(): stick a character at the end of the buffer
**
** (*++ history:
** 7 Dec 87 Bruce Eckel Creation date
** ++*)
**
** (*++ detailed:
** ++*)
*/
void char_buffer::put(char c) {
if (index +1 == length) { error("buffer overflow"); return;}
head[index++] = c;
head[index] = 0; /* null-terminate */
}
/*
-*++ char_buffer::get(): get a character from the end of the buffer
**
** (*++ history:
** 7 Dec 87 Bruce Eckel Creation date
** ++*)
**
** (*++ detailed:
** ++*)
*/
char char_buffer::get() {
if (--index < 0) { index = 0; return 0; }
char c = head[index];
head[index] = 0;
return c;
}
#ifdef TEST
main()
{
char c;
char_buffer buf(80);
while(cin.get(c), c != '\n')
buf.put(c);
cout << "dumping buf\n";
buf.dump();
}
#endif