String literals are not writeable.
Aren't you going about this a little backwards anyways? Wouldn't you have a structure that contains the header and the packet? I'm thinking something along this line:
Code:
struct packet
{
int length;
unsigned char *data;
};
struct T
{
unsigned char header[5];
struct packet packet;
};
void addPacket(struct packet *packet)
{
struct packet stuff = { 15, "45100035A0ED400" };
*packet = stuff;
}
int main()
{
struct T t = { { 'A','F','A','F','1' } };
addPacket(&t.packet);
/* ... */
return 0;
}
(Poor and unfinished and all that -- merely a poke in a different direction.)
[edit=yet another]More work in progress:
Code:
struct packet
{
int length;
unsigned char *data;
};
struct T
{
unsigned char header[5];
struct packet packet;
};
void addHeader(struct T *t)
{
unsigned char header[] = { 'A','F','A','F','1' };
memcpy(t->header, header, sizeof t->header);
}
void addPacket(struct packet *packet)
{
struct packet stuff = { 15, "45100035A0ED400" };
*packet = stuff;
}
int main()
{
struct T t;
addHeader(&t);
addPacket(&t.packet);
/* ... */
return 0;
}