buffered vs unbuffered question
I just don't spend enough time "tinkering" with *nix. Anyhow when I
read from an unbuffered input and type something in, I get two prompts
after I hit return.
m-net% more tty.c
Code:
#include <stdio.h>
int main(void)
{
char c;
return(read(0, &c, 1) == 1) ? (unsigned char)c : EOF;
return 0;
}
m-net% ./tty
c
m-net%
m-net%
Now when I buffer the input, and type something in, I only get one
prompt after I hit return.
m-net% more tty2.c
Code:
#include <stdio.h>
int main(void)
{
static char buf[BUFSIZ];
static char *bufp = buf;
static int n = 0;
if(n == 0) {
n = read(0,buf, sizeof buf);
bufp = buf;
}
return (--n >= 0) ? (unsigned char) *bufp++ : EOF;
}
m-net% ./tty2
c h a d
m-net%
Why is this?