马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我现在有两组数据,想把它合并成一个数组,求大神指点unsigned char ff[]={255,255};
unsigned char sjd[]={1,0,0,128,0,0,0,0,0,1,81,2,42,0,163,6,1,0,0,0,1,33,0,6,5,0,0,0,8,0,16,0,0,0,0,2,0,0,0,0,1,1,1,0,0,10,6,0,0,0};
本帖最后由 jackz007 于 2019-9-25 23:59 编辑
ff 和 sjd 都是通过定义得到的字符数组,所以,占用的内存空间大小就是实际元素的数量,可以通过 sizeof() 函数获取。
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
unsigned char ff[] = {255,255} ;
unsigned char sjd[] = {1,0,0,128,0,0,0,0,0,1,81,2,42,0,163,6,1,0,0,0,1,33,0,6,5,0,0,0,8,0,16,0,0,0,0,2,0,0,0,0,1,1,1,0,0,10,6,0,0,0} ;
unsigned char * p ;
int k , m , n ;
m = sizeof(ff) ;
n = sizeof(sjd) ;
p = (unsigned char *)malloc(m + n) ;
for(k = 0 ; k < m ; k ++)p[k] = ff[k] ;
for(k = 0 ; k < n ; k ++)p[k + m] = sjd[k] ;
for(k = 0 ; k < m + n ; k ++) {
if(! (k % 16)) {
if(k) printf("\n") ;
printf("\t") ;
} else {
printf(" ") ;
}
printf("%02x" , p[k]) ;
}
free(p) ;
}
|