I just want to take user input such as GET_DATE and show the date. But when I check if the client wrote GET_DATE by using strcmp it doesn't seem to work. Any assistance you can provide would be greatly appreciated.
char date_message[] = "GET_DATE";
//Receive a message from client
while ((read_size = recv(client_sock, client_message, 2000, 0)) > 0)
{
if (strcmp(client_message, date_message) == 0)
{
printf("it works");
}
else
{
printf("it doesn't work");
}
}
CodePudding user response:
The user input contains also \r\n.
You can change char date_message[] = "GET_DATE" to char date_message[] = "GET_DATE\r\n" or parse the input and then compare it as you did.
