Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

memcpy

Status
Not open for further replies.

kathyayini

Programmer
Aug 16, 2002
52
IN
I have structure called
struct senddata
{
int istatus;
char cstrmsg[50];
}sd;

char cSendBuf[100]; //char arr

I wants to copy the data of structure in to cSendBuf. i tried to copy but not successful. code is as follows

memset(&sd, '\0', sizeof(sd));
memset(cSendBuf, '\0', sizeof(cSendBuf));

strcpy(sd.cstrmsg,"Failure###");
sd.istatus = 3;
memcpy(cSendBuf,&sd,sizeof(sd));
printf("msg is :%s\n",cSendBuf);
send(sock_id,cSendBuf,10,MSG_NOSIGNAL); //socketing

what could be the problem.
 
After memcpy() cSendBuf started with int istatus member content (0x00000003). Your printing as %s terminated on this binary zeroes - that's all...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top