file_open

#include<stdio.h>
#include<stdlib.h>

#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>

int main(int argc, char *argv[])
{
int fd;
if(argc < 2)
{
puts("please input the filename!\n");
exit(1);
}

if((fd = open(argv[],O_CREAT|O_RDWR,0755)) < 0)
{
perror("open failure\n");
exit(1);
}
else
{
printf("open success fd = %d\n",fd);
}
close(fd);
exit(0);
}

打开文件的代码,如果没有要打开的,将创建!

posted on 2011-11-30 22:12  小风儿_xf  阅读(199)  评论(0编辑  收藏  举报

导航