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

专业制作网站 地摊成都到西安开车要多久

专业制作网站 地摊,成都到西安开车要多久,开鲁网站seo转接,建站模板wordpress在之前的学习中#xff0c;忘文件中写的内容都是字符串或字符#xff0c;本节学习如何写入其他各种类型的数据。 回看write和read函数的形式#xff1a; ssize_t write(int fd, const void *buf, size_t count); ssize_t read(int fd, void *buf, size_t count); 其中忘文件中写的内容都是字符串或字符本节学习如何写入其他各种类型的数据。 回看write和read函数的形式 ssize_t write(int fd, const void *buf, size_t count); ssize_t read(int fd, void *buf, size_t count); 其中第二个参数都是一个无类型的指针只不过之前一直将这里定义为一个字符串其实这个指针可以指向各种形式数据的地址。  写入一个整数 demo7.c: #include sys/types.h #include sys/stat.h #include fcntl.h #include stdio.h #include unistd.h #include string.hint main() {int fd; // file descriptionint data 100;int data2 0;fd open(./file1,O_RDWR|O_CREAT|O_TRUNC, 0600);printf(file description %d, open successfully!\n,fd);write(fd, data, sizeof(int));lseek(fd,0,SEEK_SET);read(fd, data2, sizeof(int));printf(context:%d\n,data2);close(fd); //close after writing return 0; } 运行代码 注意如果此时打开file1:此时需要使用vi打开 发现是乱码但是这并不影响程序运行时的读取和写入。 写入一个结构体 demo7.c: #include sys/types.h #include sys/stat.h #include fcntl.h #include stdio.h #include unistd.h #include string.hstruct Test {int i;char c; };int main() {int fd; // file descriptionstruct Test data {30,k};struct Test data2;fd open(./file1,O_RDWR|O_CREAT|O_TRUNC, 0600);printf(file description %d, open successfully!\n,fd);write(fd, data, sizeof(struct Test));lseek(fd,0,SEEK_SET);read(fd, data2, sizeof(struct Test));printf(data.i:%d,data.c%c\n,data2.i,data2.c);close(fd); //close after writing return 0; } 运行代码 写入一个结构体数组 demo7.c: #include sys/types.h #include sys/stat.h #include fcntl.h #include stdio.h #include unistd.h #include string.hstruct Test {int i;char c; };int main() {int fd; // file descriptionstruct Test data[2] {{30,k},{100,p}};struct Test data2[2];fd open(./file1,O_RDWR|O_CREAT|O_TRUNC, 0600);printf(file description %d, open successfully!\n,fd);write(fd, data, sizeof(struct Test)*2);lseek(fd,0,SEEK_SET);read(fd, data2, sizeof(struct Test)*2);printf(data[0].i:%d,data[0].c%c\n,data2[0].i,data2[0].c);printf(data[1].i:%d,data[1].c%c\n,data2[1].i,data2[1].c);close(fd); //close after writing return 0; } 运行代码 写入一个链表  demo7.c #include sys/types.h #include sys/stat.h #include fcntl.h #include stdio.h #include unistd.h #include string.hstruct Test {int data;struct Test *next; };int main() {int fd; // file descriptionstruct Test head {20,NULL};struct Test node1 {30,NULL};struct Test node2 {40,NULL};head.next node1;node1.next node2;fd open(./file1,O_RDWR|O_CREAT|O_TRUNC, 0600);printf(file description %d, open successfully!\n,fd);write(fd, head, sizeof(struct Test));write(fd, node1, sizeof(struct Test));write(fd, node2, sizeof(struct Test));lseek(fd,0,SEEK_SET);struct Test node_read_1 {0,NULL};struct Test node_read_2 {0,NULL};struct Test node_read_3 {0,NULL};read(fd, node_read_1, sizeof(struct Test)); read(fd, node_read_2, sizeof(struct Test));read(fd, node_read_3, sizeof(struct Test));printf(no.1%d\n,node_read_1.data);printf(no.2%d\n,node_read_2.data);printf(no.3%d\n,node_read_3.data);close(fd);return 0; } 运行代码 但是以上的代码有点笨且容错性太低首先读取和写入应该封装成函数并且我认为通常在读取链表的时候不一定知道链表有多少元素所以应该一边用尾插法动态创建链表一边读取。 改进代码demo8.c: #include sys/types.h #include sys/stat.h #include fcntl.h #include stdio.h #include unistd.h #include string.h #include stdlib.hstruct Test {int data;struct Test *next; };struct Test *insertBehind(struct Test *head, struct Test *new) {struct Test *p head;if(p NULL){head new;return head;}while(p-next ! NULL){p p-next;} //将p先移动到链表的尾部p-next new;return head; }void writeLink2File(int fd,struct Test *p){while(p ! NULL){write(fd, p, sizeof(struct Test));p p-next;} }void readLinkFromFile(int fd,struct Test *head){struct Test *new;int size lseek(fd,0,SEEK_END); //先计算文件大小lseek(fd,0,SEEK_SET); //然后不要忘记把光标移到文件头while(1){new (struct Test *)malloc(sizeof(struct Test));read(fd, new, sizeof(struct Test));printf(link data:%d\n,new-data);if(lseek(fd,0,SEEK_CUR) size){ //每次读取一个数据之后动态创建下一个链表节点之前都要判断“当前光标是否已经在文件尾”如果是说明读取已经完成printf(read finish\n);break;}head insertBehind(head,new);}}int main() {int fd; // file descriptionstruct Test head {20,NULL};struct Test node1 {30,NULL};struct Test node2 {40,NULL};head.next node1;node1.next node2;fd open(./file1,O_RDWR|O_CREAT|O_TRUNC, 0600);printf(file description %d, open successfully!\n,fd);writeLink2File(fd,head);struct Test *head_recv NULL; //准备创建一个新的链表用于接收readLinkFromFile(fd,head_recv);close(fd);return 0; } 改进代码运行
http://www.hkea.cn/news/14435200/

相关文章:

  • 图展网站源码地方电商门户网站如何建设
  • 通过域名打开网站是做映射么移动端适配
  • 个人网站服务器一年多少钱广州网站推广建设
  • e展网网站的建设情况化妆品销售网站开发与设计
  • wordpress防止cc攻击新站seo竞价
  • 做一个电子商务网站dw网页制作怎么插mp4视频
  • dede小视频网站源码wordpress主板不显示内容
  • 对网站建设的考核机制广州应用网站设计
  • 手机门户网站模板销售型网站
  • 网站开发合作合同网站设计目前和将来的就业前景
  • wordpress模板 门户网站天津做网站那家好
  • 网站权重什么意思网站模块功能
  • 可以做任务的网站有哪些内容wordpress头部调用代码
  • 做网站月薪10万wordpress移动端顶部导航栏
  • 网站职业技术培训学校wordpress是php吗
  • 上海市住房和城乡建设部官方网站秦皇岛网站制作 微商城建设
  • 织梦网站404页面模板网站设计服务合同
  • 青海城乡建设网站绍兴网站建设服务
  • 郑州网站开发比较好的网络公司十大技能培训机构排名
  • 做自主外贸网站和后台费用多少二室一厅60平米装修案例
  • 我的钢铁网网站架构影视企业宣传片制作
  • 上海网站络公司域名解析网站打不开
  • 潞城网站建设新手学纪事本html代码做网站
  • 南山网站建设公司乐云seo怀化建网站
  • 百搜网络科技有限公司沈阳网站seo排名优化
  • 建设银行分期手机网站网站设计师前景
  • wordpress仿站容易被收录不手机网站建设技术方案
  • 锡林浩特网站建设企业建设网站对客户的好处
  • 吉林律师网站建设多少钱网站开发 估算 excel
  • 上海哪家网站建设好vue做网站好吗