C中的无符号char数组串联

您所在的位置:网站首页 无符号字节数组 C中的无符号char数组串联

C中的无符号char数组串联

2024-07-15 05:26| 来源: 网络整理| 查看: 265

在C中连接无符号char数组的最佳方法是什么?此外,有没有办法将无符号char数组与char数组连接在一起?这些无符号字符数组中的2个实际上只是字符串,但为简单起见,我将它们视为无符号字符数组。

要求很复杂:有一个函数将采用1(一个)无符号char数组。一个无符号字符数组实际上是4个变量的串联,组成了1个无符号字符数组。更复杂的是,第一个无符号char数组实际上只是一个可变长度的字符串,但是其最大长度为60(即有时长度为15,其他时候为60)。

12345678910someFunctionAssignsFirst(unsigned char *first) {    //it could be 15 or 60 chars long.    ... } unsigned char first[60] = //someFunctionAssignsFirst() //This is a string i.e."variable size string max size 60" unsigned char second[8] ="always8."; //This is a string i.e."01234567" unsigned char third[32] ="always32"; //This is a cryptographic key unsigned char fourth[32] ="always32"; //This is a cryptographic key

我将如何获得:

1unsigned char allstrings[sizeof(first)+sizeof(second)+sizeof(third)+sizeof(fourth)] = //all strings combined

我尝试了一些for循环,但是可变长度first正在中断连接,我确信必须有更好的方法。

完全公开:我不是专家,我不一定爱C。此外,出于要求,不允许使用C或任何其他语言。

这就是我正在尝试做的,并且(为澄清起见)我没有在末尾得到一个空字符,因此它不是真正的字符串。

1234567891011121314151617181920212223242526unsigned char *first ="this is a sample string, human readable"; unsigned char *second ="12345678" //always a number //unsigned char third -> I have the value from before and it's a key //unsigned char fourth -> I have the value from before and it's a key unsigned char allstrings[sizeof(first) + sizeof(second) + sizeof(third) + sizeof(fourth)];     int counter = 0;     for (int i = 0; i


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3