我正在尝试从客户端读取用户名/密码,并将其传输到服务器。我也在尝试字符串的动态分配(我对它不太了解,试图学习它),而且我非常肯定存在这个问题。在最后2个printf上,我得到了一个分割错误(核被丢弃)。
int nrbytes;
char *Usercl,*Passcl;
if( read (tdl.cl, &nrbytes, sizeof(int)) <= 0 )
{
printf("[server]Thread - %d\n",tdl.idThread);
perror("Read() error\n ");
}
Usercl = new char[nrbytes+1];
if( read (tdl.cl, &Usercl, sizeof(nrbytes)) <= 0 )
{
printf("[server]Thread - %d\n",tdl.idThread);
perror("Read() error\n ");
}
if( read (tdl.cl, &nrbytes, sizeof(int)) <= 0 )
{
printf("[server]Thread - %d\n",tdl.idThread);
perror("Read() error\n ");
}
Passcl = new char[nrbytes+1];
if( read (tdl.cl, &Passcl, sizeof(nrbytes)) <= 0 )
{
printf("[server]Thread - %d\n",tdl.idThread);
perror("Read() error\n ");
}
printf("[server]Thread - %d\n. User:%s\n",tdl.idThread,Usercl);
printf("[server]Thread - %d\n. Pass:%s\n",tdl.idThread,Passcl);我得到了一个分割错误(核心抛出)在最后两个打印。
发布于 2017-01-13 20:50:19
我修好了。我做了你告诉我的一切,现在起作用了。谢谢!
发布于 2017-01-13 20:23:57
您的Usercl和Passcl已经是指针。删除他们的两个读取调用的'&‘。
https://stackoverflow.com/questions/41642760
复制相似问题