作为我作业的一部分,我需要为 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/