当前位置: 首页 > news >正文

扬中人才市场最新招聘网站优化查询

扬中人才市场最新招聘,网站优化查询,html5移动端开发,海珠区建网站1、读取文件函数原型介绍 ssize_t read(int fd,void*buf,size_t count) 参数说明: fd: 是文件描述符 buf:为读出数据的缓冲区; count: 为每次读取的字节数(是请求读取的字节数,读上来的数据保存在缓冲区buf中,同时文…

1、读取文件函数原型介绍

ssize_t read(int fd,void*buf,size_t count)

参数说明:
fd: 是文件描述符
buf:为读出数据的缓冲区;
count:   为每次读取的字节数(是请求读取的字节数,读上来的数据保存在缓冲区buf中,同时文件的当前读写位置向后移)

返回值:

 成功:返回读出的字节数
 失败:返回-1,并设置errno,如果在调用read,之前到达文件末尾,则这次read返回0

2、读取文件函数示例  

打开终端,输入以下指令:

 vi demo2.c

 接着输入如下代码:

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>int main()
{int fd;char *buf = "asdfgh!";	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("create file1 success!\n");}}printf("open susceess : fd = %d\n",fd);//	ssize_t write(int fd, const void *buf, size_t count);int n_write = write(fd,buf,strlen(buf));if(n_write != -1){printf("write %d byte to file\n",n_write);}char *readBuf;readBuf = (char *)malloc(sizeof(char)*n_write + 1);	
//	  ssize_t read(int fd, void *buf, size_t count);int n_read = read(fd, readBuf, n_write);printf("read %d ,context:%s\n",n_read,readBuf);close(fd);return 0;
}

保存退出后,输入如下指令:

gcc demo2.c 

./a.out

 3、光标移动操作

从运行结果可以看到,并未读取到内容,因为读取时候光标不在最左侧,因此需要进行光标设置。

 光标函数原型:

 off_t lseek(int fd, off_t offset, int whence);
  • 函数参数

    • fd:文件描述符

    • offset:偏移量

    • whence:位置

      • SEEK_SET:The offset is set to offset bytes. offset为0时表示文件开始位置。
      • SEEK_CUR:The offset is set to its current location plus offset bytes. offset为0时表示当前位置。
      • SEEK_END:The offset is set to the size of the file plus offset bytes. offset为0时表示结尾位置
  • 函数返回值

    • 成功返回当前位置到开始的长度
    • 失败返回-1并设置errno

 首先输入如下指令:

vi demo2.c

 输入以下代码:

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>int main()
{int fd;char *buf = "asdfghi!";	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("create file1 success!\n");}}printf("open susceess : fd = %d\n",fd);int n_write = write(fd,buf,strlen(buf));if(n_write != -1){printf("write %d byte to file\n",n_write);}char *readBuf;readBuf = (char *)malloc(sizeof(char)*n_write + 1);	lseek(fd, 0, SEEK_SET);int n_read = read(fd, readBuf,100);printf("read %d ,context:%s\n",n_read,readBuf);close(fd);return 0;
}

 保存,输入以下指令:

gcc demo2.c

./a.out

 运行结果如下:

 

http://www.zhongyajixie.com/news/7211.html

相关文章:

  • 如何建立网站视频安徽网站设计
  • 网站建设营销话术谷歌站长平台
  • 响应式 网站建设厦门网络营销推广
  • 物联网 网站开发关键词热度分析
  • 网站排名优化+o+m关键词推广优化排名如何
  • 在香港做网站需要什么软件西安官网seo
  • 山东网站建设谷歌关键词排名查询
  • 家用电脑做网站网页制作在线生成
  • 环保企业的网站怎么做百度官网认证多少钱一年
  • b2b网站一个人可以做吗江西百度推广公司
  • 想学电商运营在哪里学关键词优化靠谱推荐
  • 网站架构优化网站广告接入
  • 做网站送给女友意义上海网络seo公司
  • 在线建站宣传网站有哪些
  • 怎么建php网站seo快速提升排名
  • 精神文明建设专题网站怎么做盲盒
  • 商城网站源码下载网络培训学校
  • 怎么注册企业邮箱号seo网站建设是什么意思
  • 温州建站平台泸州网站优化推广
  • 嘉兴网站建设一薇提高工作效率的句子
  • 西宁网络公司网站建设代运营公司是怎么运营的
  • 福建省漳州市政府网站建设情况黑科技推广软件
  • 美食电子商务网站建设规划书seo教程技术资源
  • wordpress多用户多界面百度广告优化师
  • 衡水做企业网站网页推广平台
  • 济南专门做公司网站的公司百度关键词搜索排行榜
  • 武威 网站开发百度推广总部电话
  • 中华人民住房和城乡建设部网站长沙靠谱seo优化
  • 做哪个网站的直播好汨罗网站seo
  • 郑州网站建设与制作网络的推广