c - 尝试使用 Open Function 调用时出现错误消息

标签 c system-calls xv6

作为我作业的一部分,我需要为 XV6 创建一个小型 C 程序。该程序必须创建一个文件,写入文件,然后关闭它。

当我尝试用我的文件编译 xv6 时,我收到两条错误消息。

HWC2.c:13:82: error: ‘O_CREAT’ undeclared (first use in this function)
 fd = open("/home/kyle/Desktop/Projects/'Assignment 2'/xv6/Tom.txt", O_RDWR | O_CREAT);
                                                                              ^
HWC2.c:13:14: error: called object ‘open’ is not a function or function pointer
 fd = open("/home/kyle/Desktop/Projects/'Assignment 2'/xv6/Tom.txt", O_RDWR | O_CREAT);

我是 C 编程新手,所以我仅限于通过 google 搜索找到的内容,但没有任何帮助。相反,我尝试只使用 write 来代替 O_CREAT

#include "types.h"
#include "stat.h"
#include "user.h"

int open;
int fd;

int main (void)
{

    printf(1,"My Name\n");
    fd = open("/home/kyle/Desktop/Projects/Assignment 2/xv6/Tom.txt", O_RDWR | O_CREAT);

    write(fd, "1 2 3 4", 7);
    close(fd);

}

我需要它来编译、打印我的名字、创建文件、写入文件,然后保存并关闭文件

最佳答案

尝试包含

#include <fcntl.h>
#include <stdio.h>

要打印姓名,您可以尝试:

printf("%s\n", "My Name");

关于c - 尝试使用 Open Function 调用时出现错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57913483/

相关文章:

c - gnuc 中的可变长度结构

Delphi 汇编调用

c - syscall() 中的 xv6 rev6 奇怪代码

iphone - UDP sendto() 没有可用的缓冲区空间

c - 缓冲区溢出漏洞: sh: 1: Syntax error: Unterminated quoted string : Developing exploit for personal enrichment

c++ - 如何在 GCC 中弃用 C 预处理器宏?

linux-kernel - linux系统调用实现

c - 如何使用系统调用Read?段错误(核心转储)错误

在 qemu-system-misc 包中找不到 qemu-system-riscv64

c - xv6: 不使用 ticks 锁直接读取 ticks?