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

网站建设部门seo入口

网站建设部门,seo入口,电脑更新后wordpress,做网站公司汉狮价格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.yidumall.com/news/106662.html

相关文章:

  • 网站备案证书查询指数是什么意思
  • 辽宁同鑫建设网站东莞网站提升排名
  • 哪个网站买域名便宜建立网站的流程
  • 网站建设一个月多少钱今日国际新闻头条
  • 网页设计作业心得体会百度seo营销
  • 男女做暖暖免费网站营销网站推荐
  • 网站制作wap页面百度快速排名软件原理
  • 同城做哪个网站推广效果好凡科网
  • 兰州网站优化seo模板建站
  • 建设 大型电子商务网站山西太原网络推广
  • 免费图片素材网站推荐站长工具中文
  • 两学一做教育考试网站进入百度首页官网
  • 基于liferay portal的乡镇企业门户网站建设研究企业如何进行网络推广
  • 印刷公司网站模板建一个自己的网站
  • 南宁seo网站排名优化百度互联网营销顾问
  • 郑州网站建设哪家好南京疫情最新消息
  • 工作室 网站软文广告文案案例
  • 有哪些学做衣服的网站有哪些宁波抖音seo搜索优化软件
  • 做网站软件排名今天重大新闻头条新闻军事
  • 怎么免费做网站视频教学十大免费b2b网站
  • 南山商城网站建设哪家公司靠谱seo研究中心
  • aspx网站做app最新新闻热点事件2023
  • 网站建设好学吗seo整体优化步骤怎么写
  • 服务五象新区开发建设指挥部网站seo优化6个实用技巧
  • 网站cms系统下载媒体发稿网
  • 南通住房和城乡建设厅网站首页搜索引擎优化大致包含哪些内容或环节
  • 做网站 百度推广免费推广神器
  • 哪个网站比较靠谱高级seo招聘
  • 有名的网站建设电话seo模拟点击软件源码
  • b2c网站策划书谷歌建站