int main(int argc, char **args) {
unsigned char* str = "hallo";
printf("String: %s\n",str);
uint8_t aktion, id;
uint32_t str_length;
aktion = 1;
id = 4;
str_length = strlen(str)+1;
unsigned char *buff;
buff = (unsigned char*) calloc(1,str_length+6);
memcpy(buff, &id, sizeof(id));
memcpy(buff+sizeof(id), &str_length, sizeof(str_length));
strcpy(buff+sizeof(id)+sizeof(str_length), str);
printf("Buffer+5: %s\n",buff+5));
memcpy(buff+sizeof(id)+sizeof(str_length)+str_length, &aktion, sizeof(aktion));
return 0;
}
为什么我没有得到输出“你好”?我仍然不确定是否使用指针算法和缓冲区。
问候