【发布时间】:2012-06-19 09:51:03
【问题描述】:
首先抱歉,如果这是一个愚蠢的问题(肯定是),但我对 Unix 中 Syscall 的使用真的很陌生。 我试图使用“write”在文件上写一些东西;它正确地创建了文件,但是上面没有写任何东西,这就是代码:
int main(void) {
int fd;
char *string = "Test";
if(fd=open("home/user/test.txt", O_WRONLY | O_APPEND | O_CREAT)==-1){
perror("Open failed");
}
printf("%d\n", strlen(string));
printf("Wrote %d byte on the file", write(fd,string,strlen(string)));
close(fd);
return 0;
}
我的问题在哪里? 谢谢
【问题讨论】:
-
写返回什么?你在第二个 printf 中得到了什么?
标签: c linux file unix system-calls