我有C語言編寫的一個簡單的echo服務器,我想停止服務器,如果它收到quit
字我該如何比較recived answer?
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);
}
}
我怎樣才能比較接收緩衝區的字符串?
有什麼問題上面的代碼? – 2012-07-21 09:51:00
我一直都想與1個 – 2012-07-21 09:52:45
@iUngi:..你在哪裏得到1? – Ashe 2012-07-21 09:53:07