Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在按下 CTRL+D 之前,我一直无法从标准输入读取。我必须read()从 unistd.h 使用。我正在尝试模拟 cat 功能。有没有办法让我的缓冲区(我用 %s 打印)看起来整洁而没有不必要的空格read(STDIN_FILENO, buf, 256)?
read()
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. */ }