这是家庭作业的一部分.好吧,我的作业无法正常工作,所以我已经把一个片段拿出来并开始用它来弄清楚什么是错的.
在C语言的Linux上我试图打开/创建一个文本文件,给它写一些东西,关闭它,在读/写和追加模式下打开它,然后在它的末尾添加任何东西(在这个例子中,字符串",老兄").但是没有附加任何内容,但write方法也没有抛出错误.我不确定是什么.
这是代码:
#include
#include
#include
#include
#include
#include
#include
#define BUFFSIZE 4096
int main(){
mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
int fd = open("tempfile.txt", O_RDWR | O_CREAT, mode);
char buf[BUFFSIZE] = {'t', 'h', 'y', ' ', 'f', 'a', 'l', 'l'};
size_t n = sizeof(buf);
if(write (fd, buf, n) < 0){
printf("Error in write\n");
printf("%s", strerror(errno));
return 1;
}
close(fd);
int fd2 = open("temp