函数名:creat
头文件:
函数原型: int creat(const char *file,int auth);
功能: 创建指定文件名的文件
参数:char *file 要创建的文件名 , int auth 为操作权限
返回值: 成功 返回文件句柄 ,失败 返回-1
程序例: 创建一个文件,然后输入内容,该函数创建文件不能覆盖同名的文件#include
#include
#include
int main(void){
char filename[80];
printf("input file path and file name,eg d:\\a.txt: ");
gets(filename);
int fd=creat(filename,O_RDONLY);
if(fd==-1){
printf("can not create the file\n");
return 1;
}
printf("successful to create the file\n");
close(fd);
return 0;
}
运行结果input file path and file name,eg d:\a.txt: d:\c.txt
successful to create the file