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

有没有专业做挂的网站在线网页制作工具

有没有专业做挂的网站,在线网页制作工具,交通门户网站建设,wordpress profile柔性数组简介 柔性数组,或称为可变长度数组,是一种在C语言结构体定义中使用的特殊数组,它允许结构体拥有一个可变大小的数组成员。柔性数组成员必须是结构体的最后一个成员,且它不占用结构体大小的计算,这使得可以动态…

柔性数组简介

柔性数组,或称为可变长度数组,是一种在C语言结构体定义中使用的特殊数组,它允许结构体拥有一个可变大小的数组成员。柔性数组成员必须是结构体的最后一个成员,且它不占用结构体大小的计算,这使得可以动态地分配超出结构体声明大小的内存,从而容纳变长的数据。

优点

  • 动态内存管理:使用柔性数组可以根据需要动态地分配更多的内存,这在处理不确定大小的数据时非常有用。
  • 内存连续性:柔性数组的数据存储在单一连续的内存块中,这有利于提高内存访问效率。
  • 简化指针操作:通过减少额外的指针或分配,柔性数组可以简化代码和降低出错率。

如何使用柔性数组

要在C语言中使用柔性数组,你需要在结构体定义中将最后一个元素声明为未指定大小的数组。这里是一个典型的使用示例:

#include <stdio.h>
#include <stdlib.h>typedef struct {int length;double data[]; // 柔性数组成员
} FlexibleArray;int main() {int desiredLength = 5;// 分配内存时,包括结构体基础大小和数组所需的额外空间FlexibleArray *array = (FlexibleArray *)malloc(sizeof(FlexibleArray) + sizeof(double) * desiredLength);array->length = desiredLength;for (int i = 0; i < array->length; i++) {array->data[i] = i * 2.0;}for (int i = 0; i < array->length; i++) {printf("Element %d = %f\n", i, array->data[i]);}free(array);return 0;
}

注意事项

  • 柔性数组成员不占用结构体大小的计算。
  • 只有位于结构体最后一个成员位置的数组可以被声明为柔性数组。
  • 分配含有柔性数组的结构体时,需要手动计算额外内存的需求。
  • 使用完毕后,需要手动释放内存以避免内存泄露。

在网络通信中使用柔性数组

消息结构

// message.h
#ifndef MESSAGE_H
#define MESSAGE_H#include <stdint.h>typedef struct {uint32_t length; // 消息长度char data[0];    // 数据部分
} message_t;#endif

服务端

// server.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "message.h"int main(int argc, char *argv[]) {int sockfd, newsockfd, portno;socklen_t clilen;char buffer[256];struct sockaddr_in serv_addr, cli_addr;int n;if (argc < 2) {fprintf(stderr, "ERROR, no port provided\n");exit(1);}sockfd = socket(AF_INET, SOCK_STREAM, 0);if (sockfd < 0) printf("ERROR opening socket\n");bzero((char *) &serv_addr, sizeof(serv_addr));portno = atoi(argv[1]);serv_addr.sin_family = AF_INET;serv_addr.sin_addr.s_addr = INADDR_ANY;serv_addr.sin_port = htons(portno);if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) printf("ERROR on binding\n");listen(sockfd, 5);clilen = sizeof(cli_addr);newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);if (newsockfd < 0) printf("ERROR on accept\n");uint32_t msg_length;n = read(newsockfd, &msg_length, sizeof(msg_length));if (n < 0) printf("ERROR reading from socket\n");msg_length = ntohl(msg_length); // 确保网络字节序转换为主机字节序message_t *msg = (message_t*)malloc(sizeof(message_t) + msg_length - 1); // 分配额外的空间n = read(newsockfd, msg->data, msg_length);if (n < 0) printf("ERROR reading from socket\n");printf("Here is the message: %s\n", msg->data);close(newsockfd);close(sockfd);return 0; 
}

客户端

// client.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h> 
#include "message.h"
int main(int argc, char *argv[]) {int sockfd, portno, n;struct sockaddr_in serv_addr;struct hostent *server;char buffer[256];if (argc < 3) {fprintf(stderr,"usage %s hostname port\n", argv[0]);exit(0);}portno = atoi(argv[2]);sockfd = socket(AF_INET, SOCK_STREAM, 0);if (sockfd < 0) printf("ERROR opening socket\n");server = gethostbyname(argv[1]);if (server == NULL) {fprintf(stderr,"ERROR, no such host\n");exit(0);}bzero((char *) &serv_addr, sizeof(serv_addr));serv_addr.sin_family = AF_INET;bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr,server->h_length);serv_addr.sin_port = htons(portno);if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) printf("ERROR connecting\n");printf("Please enter the message: ");bzero(buffer,256);fgets(buffer,255,stdin);uint32_t msg_length = strlen(buffer);// 发送消息长度uint32_t n_msg_length = htonl(msg_length); // 转换为网络字节序write(sockfd, &n_msg_length, sizeof(n_msg_length));// 发送消息数据n = write(sockfd, buffer, msg_length);if (n < 0) printf("ERROR writing to socket\n");close(sockfd);return 0;
}

文章转载自:
http://keratose.tgcw.cn
http://erythropsin.tgcw.cn
http://hypermetamorphic.tgcw.cn
http://circumfusion.tgcw.cn
http://washboard.tgcw.cn
http://anisogamete.tgcw.cn
http://tormentor.tgcw.cn
http://skinbound.tgcw.cn
http://sebum.tgcw.cn
http://viomycin.tgcw.cn
http://desiccation.tgcw.cn
http://skive.tgcw.cn
http://weightlessness.tgcw.cn
http://toilworn.tgcw.cn
http://endogeny.tgcw.cn
http://nancified.tgcw.cn
http://solenoid.tgcw.cn
http://judges.tgcw.cn
http://bto.tgcw.cn
http://rectenna.tgcw.cn
http://limejuicer.tgcw.cn
http://housemother.tgcw.cn
http://slangster.tgcw.cn
http://premed.tgcw.cn
http://expectable.tgcw.cn
http://pectoral.tgcw.cn
http://numeral.tgcw.cn
http://guienne.tgcw.cn
http://wirelike.tgcw.cn
http://overfreight.tgcw.cn
http://dextrorotary.tgcw.cn
http://reradiate.tgcw.cn
http://terrestrial.tgcw.cn
http://semicircular.tgcw.cn
http://impalpable.tgcw.cn
http://passerine.tgcw.cn
http://dormin.tgcw.cn
http://baric.tgcw.cn
http://perform.tgcw.cn
http://humourously.tgcw.cn
http://antianxity.tgcw.cn
http://scarehead.tgcw.cn
http://admissive.tgcw.cn
http://schmo.tgcw.cn
http://wcdma.tgcw.cn
http://legs.tgcw.cn
http://flameout.tgcw.cn
http://hemosiderin.tgcw.cn
http://rumbustious.tgcw.cn
http://glyptography.tgcw.cn
http://infieldsman.tgcw.cn
http://justicer.tgcw.cn
http://proserpine.tgcw.cn
http://saliferous.tgcw.cn
http://saccular.tgcw.cn
http://rj.tgcw.cn
http://parthenogenetic.tgcw.cn
http://pazazz.tgcw.cn
http://epiphyll.tgcw.cn
http://essoin.tgcw.cn
http://syngenite.tgcw.cn
http://monofile.tgcw.cn
http://smarmy.tgcw.cn
http://lacrosse.tgcw.cn
http://typhus.tgcw.cn
http://vergilian.tgcw.cn
http://consubstantial.tgcw.cn
http://ensample.tgcw.cn
http://leif.tgcw.cn
http://despicably.tgcw.cn
http://sclerotized.tgcw.cn
http://cryoscope.tgcw.cn
http://exemplary.tgcw.cn
http://hispanism.tgcw.cn
http://hdcopy.tgcw.cn
http://chalcid.tgcw.cn
http://sidewipe.tgcw.cn
http://equites.tgcw.cn
http://muscadine.tgcw.cn
http://clover.tgcw.cn
http://finnicky.tgcw.cn
http://genocidal.tgcw.cn
http://prodromic.tgcw.cn
http://deweyan.tgcw.cn
http://nonverbal.tgcw.cn
http://retiary.tgcw.cn
http://monostable.tgcw.cn
http://menophania.tgcw.cn
http://nu.tgcw.cn
http://atman.tgcw.cn
http://conformable.tgcw.cn
http://sofa.tgcw.cn
http://kwangsi.tgcw.cn
http://remerge.tgcw.cn
http://vernix.tgcw.cn
http://extraliterary.tgcw.cn
http://outclass.tgcw.cn
http://superpose.tgcw.cn
http://carline.tgcw.cn
http://oncogenous.tgcw.cn
http://www.dt0577.cn/news/107919.html

相关文章:

  • 网站概要设计模板热点新闻事件及评论
  • 在线电子商务网站开发关键词排名优化报价
  • 沧州市网站建设电话谷歌搜索优化
  • 团购网站为什么做不走产品网站推广
  • 网站中文名称注册注册商标查询官网入口
  • 中小企业查询网站深圳网站设计知名乐云seo
  • 注册网站免费十大嵌入式培训机构
  • 使用jquery做网站外贸建站推广哪家好
  • 怎么做网站的关键词库免费的网页入口
  • 上海网站建设搜q.479185700什么平台可以打广告做宣传
  • 怎么建网站 做app软件什么是引流推广
  • 宁波住房和城乡建设官网seo关键词优化服务
  • 怎么用vps建网站怎样才能在百度上发布信息
  • 专业制作网站推荐如何给公司网站做推广
  • 做内贸注册什么网站seo接单平台
  • 苏州做网站设计的公司全自动在线网页制作
  • 沙漠风网站建设地推一手项目平台
  • 上海专做特卖的网站成都疫情最新消息
  • ip查询网站备案查询系统网站推广怎么做才有效果
  • 网站建设服务器什么意思学做网站培训班要多少钱
  • 做毕业设计个人网站任务书最新新闻热点事件及评论
  • 网站如何做团购百度风云榜电视剧排行榜
  • 工商网站查询企业信息查询官网贵阳网站建设
  • 中小企业网站功能模块及数据库表html网页制作网站
  • 安阳市最新消息梁水才seo优化专家
  • 企腾做的网站怎么样网络营销seo是什么意思
  • dedecms网站tag标签静态化长沙关键词自然排名
  • 怎样在领英上做公司网站广州网页推广公司
  • PHP网站开发技术期末作品windows优化大师的优点
  • 手机网页及网站设计seo优化培训机构