Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Empty String From recv() return

I am writing a small c socket program. However a call to recv() indicates that 32 bytes of data was received, however calling fprintf as below displays a blank line to the console. What beats me is that data actually returns but printing blank lines. Is it possible I am using the wrong format specifier for fprintf?

messagesize = recv(socketHandle, recvbuffer, sizeof(recvbuffer), 0);

fprintf(stdout, "%d bytes read <<< ping message \n", messagesize);

recvbuffer[messagesize] = '\0';

fprintf(stdout, "message received : %s\n\n", (char *) recvbuffer);

Comments