quit
我有一个用 C 编写的简单回显服务器,如果它收到这个词,我想停止服务器
int n;
char buffer[256];
while(strcmp(buffer,"quit") != 0)
{
n = read(sock,buffer,255);
if (n < 0)
{
perror("ERROR reading from socket");
exit(1);
}
printf("Here is the message: %s\n",buffer);
printf("%d-%d\n", sizeof(buffer), strcmp(buffer,"quit"));
n = write(sock,"I got your message",18);
if (n < 0)
{
perror("ERROR writing to socket");
exit(1);
}
}
如何将接收到的缓冲区与字符串进行比较?