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

西安网站架设公司如何网上免费打广告

西安网站架设公司,如何网上免费打广告,南京做网站设计,乡村振兴网站建设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.hkea.cn/news/727584/

相关文章:

  • 梧州网站推广方案百度热搜 百度指数
  • 网站不兼容ie6自助建站模板
  • 甘肃网站建设公司百中搜优化软件
  • 国内外贸网站建设公司seo教程 百度网盘
  • 一物一码二维码生成系统最好用的系统优化软件
  • 如何在大网站做外链镇江网站建站
  • 杭州网站建设公司导航短视频营销案例
  • 昆明做网站建设有哪些长尾关键词排名工具
  • 一女被多男做的视频网站网站seo系统
  • 网站建设 青海网站建设找哪家好
  • win7 网站配置优化方案官网电子版
  • 广州seo优化公司排名浙江seo博客
  • 全网推广的方式有哪些抖音seo推荐算法
  • 网站开发开源架构抖音营销软件
  • 自己做的网站能放到网上么青岛seo经理
  • 营业推广策划方案邵阳网站seo
  • 手机网站横向切换kol合作推广
  • 专门做超市海报的网站宁波seo咨询
  • 仿网站上的焦点图在线看seo网站
  • 做网站的业务员艾滋病阻断药有哪些
  • web集团网站建设广告投放平台有哪些
  • 大连做网站建设广告资源对接平台
  • 做网站怎么写工作日志泉州网站seo公司
  • wordpress外链站内打开搜索引擎是什么意思啊
  • 做论坛网站需要什么备案新站seo优化快速上排名
  • 动漫网站html百度网盘搜索
  • 怎么看一个网站什么语言做的宝鸡seo培训
  • 数据库网站建设公司他达拉非片
  • 英文商城网站建设搜索引擎营销的特点
  • 易优建站系统图片百度搜索