I have a simple echo server written in C, I would like to stop the server if it received the quit word
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);
}
}
How can I compare the received buffer with a string?
I figured it out
How to remove \n or \t from a given string in C?