#include <stdio.h>
#define MAXLEN 256
int main() {
int n;
char buf[MAXLEN];
while((n = read(0,buf,sizeof(buf))) != 0){
printf("n: %d:",n);
write(1,buf,n);
}
return 1;
}
Run Code Online (Sandbox Code Playgroud)
程序的输出(第一个read
和第一个write
由用户键入并由终端回显)是:
read
read
write
write
n: 5:n: 6:
Run Code Online (Sandbox Code Playgroud)
printf的输出在标准输入处按Ctrl + D后出现,而不是随后的读取.为什么会这样?