c - systemcalls.h 找不到这样的文件或目录

标签 c unix system-calls

我正在阅读 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/

相关文章:

mysql - 查看 "open file descriptors"

linux - Bash enter & ctrl-z 按键

linux - 程序集执行失败-14

C 编译器使用常量的默认行为

c - 使用 read(..) 从 stdin 读取并计算出缓冲区的大小

C 缩小循环缓冲区的大小

bash - 在 bash 中提取多个字符串并合并为 .csv

linux - 如何将 sysenter 用于链接到 SystemⅤ 库的 64 位用户态程序?

linux - 什么时候应该使用系统调用函数而不是 glibc 包装器?

c - 关于具有左节点、右节点和父节点的树数据结构的教程