所以我试图将缓冲区与 strcmp 的字符串进行比较。我希望服务器在客户端说“人”时以特殊方式响应,否则只是回复得到它。我看不出我做错了什么,但我的输出总是“得到它”而不是man,即使我从客户端输入man也是如此。
void dostuff (int sock)
{
int n;
char buffer[256];
bzero(buffer,256);
n = read(sock,buffer,255);
//make list match each get text and match to user
if (n < 0) error("ERROR reading from socket");
if (!strcmp ( buffer, "man" )) n = write(sock,"you are manly",18);
else{ printf("Here is the message: %s\n",buffer);
n = write(sock,"got it",18);};
//n = write(sock,"you are gay",18);
if (n < 0) error("ERROR writing to socket");
/*
if (n < 0) error("ERROR reading from socket");
printf("Here is the message: %s\n",buffer);
n = write(sock,"got it",18);
if (n < 0) error("ERROR writing to socket");*/
}