how to force a buffer to behave like a string in C?

Asked

Viewed 111 times

1

I am receiving a buffer from the internet, I believe that to go through this buffer and find the last character, you need to find the character ' 0'. But there is no ' 0' in a buffer.

It is possible to force this buffer to behave like a string?

1 answer

2

Adds p '\0' buffer. But attention to binary data!!

length = recv(socket, buffer, sizeof buffer - 1, 0);
buffer[length] = 0; // adiciona terminador

Browser other questions tagged

You are not signed in. Login or sign up in order to post.