#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h> //write所需要的头文件和函数原型 可以使用 man write 查找
#include <string.h>
int main()
{
int fd;
char *buf = "ChenLiChen hen shuai!"; //linux环境下指针是8个字节
fd = open("./file1",O_RDWR);
if(fd == -1){
printf("open file1 failed\n");
fd = open("file1",O_RDWR|O_CREAT,0600);
if(fd > 0){
printf("creat file1 success!\n");
}
}
printf("open success : fd = %d\n",fd);
// 函数原型 ssize_t write(int fd, const void *buf, size_t count);
write(fd,buf,strlen(buf)); //将buf指向的字符串写入file中
//写入此功能后write也有一个非负整数返回值
close(fd); //关闭文件
return 0;
}