#include<unistd.h> #include<sys/types.h> #include<sys/stat.h> #include<fcntl.h> #include<stdio.h> int main() { int fd,size; char s []="Linux Programmer!\n",buffer[80]; fd=open("/root/Documents/kkkkk/leijiangtao/myfile",O_WRONLY|O_CREAT); write(fd,s,sizeof(s)); close(fd); fd=open("/root/Documents/kkkkk/leijiangtao/myfile",O_RDONLY); size=read(fd,buffer,sizeof(buffer)); printf("%s",buffer); close(fd); return 0; } //"/root/Documents/leijiangtao/myfile"这句一定要写完整尤其是root前面的那个/ //myfile后面加不加后缀无所谓 //再就是要注意汉子的符号 /* [[email protected] 已利用]# gcc open.c [[email protected] 已利用]# ./a.out Linux Programmer! [[email protected] 已利用]# */
时间: 2024-11-09 00:37:06