Since you only actually need one \0, you can do this
Code:int data_lenght = recv(fd, buffer, sizeof(buffer)-1, 0); // allow for a \0 if ( data_lenght > 0 ) buffer[data_lenght] = '\0';
Since you only actually need one \0, you can do this
Code:int data_lenght = recv(fd, buffer, sizeof(buffer)-1, 0); // allow for a \0 if ( data_lenght > 0 ) buffer[data_lenght] = '\0';
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.