我正在阅读 K&R 的 C 编程,我刚刚开始最后一章:UNIX 系统接口(interface)。我遇到了一个进行系统调用的文件复制代码。首先,我在 codeblocks 窗口中编译了该代码,但出现找不到目录/文件的错误,然后我想我应该在 Linux 中编译该代码。但是之后我得到了同样的错误。
我在 stackoverflow 上阅读了一些其他问题: sudo apt-get 更新 然后再次安装 linux header
读到某处使用 syscall.h 但 BUFSIZ 没有在其中定义,我认为这本书没有错。
#include "syscalls.h"
int main()
{
char buf[BUFSIZ];
int n;
while((n = read(0, buf, BUFSIZ)) > 0)
write(1, buf, n);
return 0;
}
最佳答案
#include <unistd.h>
#include<stdio.h>
main()
{
char buf[BUFSIZ];
int n;
while((n = read(0,buf,BUFSIZ))>0)
write(1,buf,n); //Output to the Console
return 0;
}
编辑 unistd.h
可以使用。也修正了拼写错误!
输出:
myunix:/u/mahesh> echo "Hi\nWorld" | a.out
Hi
World
关于c - systemcalls.h 找不到这样的文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24898450/