There is a code area:

cin.getline(b, 200, '\n'); send(s, b, sizeof(b), 0); if (strcmp(b, "sms") && (b[3] =='\0')) { recv(s, b, sizeof(b), 0); cout << b << endl; } 

Task - if the entered string is "sms", then get a specific string from the server and display it on the screen. However, for some reason, the program does not enter the condition body, it is not clear for what reason. I watched for debugging, the first 3 characters of the string entered from the keyboard are 's' 'm' 's' , and the fourth is '\0' . Therefore, I do not understand what the problem is.

  • Because if the strings are equal, then strcmp returns NULL - andreymal

1 answer 1

Replace

 if (strcmp(b, "sms") && (b[3] =='\0')) { 

on

 if (strcmp(b, "sms") == 0) {