我有麻烦从stdin不断读取,直到按下CTRL+D。我必须用unist。h中的read()
。我试着模拟cat函数。是否有一种方法可以使我的缓冲区(我用%s打印)看起来整洁,而不需要read(STDIN_FILENO, buf, 256)
中的不必要的空格?
我正在尝试模拟cat函数。
开头:
ssize_t nread, nwrite;
while ((nread = read(STDIN_FILENO, buf, sizeof buf)) > 0) {
nwrite = write(STDOUT_FILENO, buf, nread);
/* Error handling and partial writes left as exercise. */
}