J
Jeff
Im trying to memcpy a buffer from a filled in simple structure.
When I memcpy and then print the resulting buffer, I see 7 locations
that have junk before my data starts. My data structure is:
struct command_pkt {
char command_num[3];
char command[100];
};
typedef command_pkt COMMAND;
The relevant portion is the following:
sprintf(tmp,"%s %s",ip,host);
COMMAND *com;
strcpy(com->command_num,"1");
strcpy(com->command,tmp);
int len = sizeof(COMMAND);
unsigned char buf[200];
if (len > 200) {
printf("ERROR - len > buf\n");
return -1;
}
memset(&buf[0],0,200);
memcpy(&buf[1],(unsigned char *)&com,len);
printf("COM buf: <%s>\n",buf);
Any ideas why there is junk at the beginning of my buffer?
When I memcpy and then print the resulting buffer, I see 7 locations
that have junk before my data starts. My data structure is:
struct command_pkt {
char command_num[3];
char command[100];
};
typedef command_pkt COMMAND;
The relevant portion is the following:
sprintf(tmp,"%s %s",ip,host);
COMMAND *com;
strcpy(com->command_num,"1");
strcpy(com->command,tmp);
int len = sizeof(COMMAND);
unsigned char buf[200];
if (len > 200) {
printf("ERROR - len > buf\n");
return -1;
}
memset(&buf[0],0,200);
memcpy(&buf[1],(unsigned char *)&com,len);
printf("COM buf: <%s>\n",buf);
Any ideas why there is junk at the beginning of my buffer?