【发布时间】:2019-11-27 15:53:49
【问题描述】:
如何使用 write() 系统调用将整数写入文件
//write(fd,buffer,strlen(buffer));
//The buffer in the write() system call has to be an char[];
//if i want to write integer such as
for(int i = 0, i < 10; i++){
write(fd,i.??); // error
// How can i write the integer in to the file by using the write() system call
}
【问题讨论】:
-
write(fd, &i, sizeof i); -
这将写入适合
write使用的二进制值。如果您想要文本表示,请使用fprintf。
标签: c filesystems buffer system-calls