码迷,mamicode.com
首页 > 其他好文 > 详细

open函数例子

时间:2014-11-20 16:51:20      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   os   sp   on   div   

#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后面加不加后缀无所谓
//再就是要注意汉子的符号
/*
[root@linux 已利用]# gcc open.c
[root@linux 已利用]# ./a.out
Linux Programmer!
[root@linux 已利用]# 
*/

 

open函数例子

标签:style   blog   io   ar   color   os   sp   on   div   

原文地址:http://www.cnblogs.com/leijiangtao/p/4110887.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!