Re: memcpy junk at beginning of buffer



Sorry, i realized a couple things after I posted this.

Here's the fully independent version, also fixed char out
issue vs COMMAND struct:

#include <string.h>
#include <stdlib.h>
#include <stdio.h>

struct command_pkt {
char command[100];
};

int main()
{
char out[20];
strcpy(out,"buffer data");

struct command_pkt *com;
com = (struct command_pkt *)malloc( sizeof(struct command_pkt) );
strcpy(com->command,out);

printf("\tCom send: %s\n",com->command);

int len = sizeof(struct command_pkt);
unsigned char buf[300];

memcpy(&buf[0],(unsigned char *)&com,len);
printf("COM SENDING: <%s>\n",com->command);
printf("COM buf: <%s>\n",buf);

return 0;
}

.



Relevant Pages