creat 注意没有e
函数原型
int fd = creat(char *path, mode_t mode);
参数
path 是创建/重写文件的路径名
mode 就是访问模式了
返回值
如果创建或重写失败了,那么会返回-1
如果成功 那么将返回它的文件描述符
①创建
int fd = creat(“TestCreate.txt”,0744);
权限为rwxr–r--
②重写的话 那就是清空了文件内容,文件长度为0
代码
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
int fd = creat("TestCreate.txt",0744);
if(-1 != fd)
{
printf("Create success\n");
close(fd);
}
else
{
printf("Create fail\n");
}
return 0;
}