各位大侠,我用套接字发送一个结构体,如下:
struct BasicInformation
{
char name[10];
char sex[2];
char year[5];
char month[3];
char day[3];
char password[8];
char zipcode[10];
char qq[10];
char phone[12];
char noPublic[2];
char photo[3];
char email[20];
};
BasicInformation bi;
........///给bi的各个成员赋值
///////////////////////////////////////如果要此处加入:MessageBox(bi的任一成员),则服务器方完全正常!
客户机发送套接字:send(client,(char *)&bi,sizeof(BasicInformation),0);服务器接收结构体:
char* buf;
buf=new char[sizeof(BasicInformation)];
ret=recv(client,buf,sizeof(BasicInformation),0);
bi=(BasicInformation*)buf;
在服务器端输出bi的各个位是出现乱码!
struct BasicInformation
{
char name[10];
char sex[2];
char year[5];
char month[3];
char day[3];
char password[8];
char zipcode[10];
char qq[10];
char phone[12];
char noPublic[2];
char photo[3];
char email[20];
};
BasicInformation bi;
........///给bi的各个成员赋值
///////////////////////////////////////如果要此处加入:MessageBox(bi的任一成员),则服务器方完全正常!
客户机发送套接字:send(client,(char *)&bi,sizeof(BasicInformation),0);服务器接收结构体:
char* buf;
buf=new char[sizeof(BasicInformation)];
ret=recv(client,buf,sizeof(BasicInformation),0);
bi=(BasicInformation*)buf;
在服务器端输出bi的各个位是出现乱码!
BasicInformation bi;
memset(&bi,0,sizeof(BasicInformation));
ret=recv(client,&bi,sizeof(BasicInformation),0);
比如 char RecvBuf[1024]={0};
2.主意下面的问题:
对象初始化
BasicInformation bi;
memset(&bi,0,sizeof(BasicInformation));
ret=recv(client,&bi,sizeof(BasicInformation),0);
3.指针初始化:
char* buf;
buf=NULL;