So I have a character array of fixed size:
char buff[100];
And I have a character pointer:
char *ptr;
Now, the buffer will be filled partially or fully. I want to copy the contents of the buffer to ptr. How do I do that?
Thanks
Update:
int rcd; // Received bytes
int temp = 0; // This is used as a size to realloc the dataReceived character pointer
int packetLength = 0; // This is the total packet length
int *client = (int*) data;
int cli = *client; // The client socket descriptor
char buff[100]; // Buffer holding received data
char *dataReceived = malloc(0);
while ((rcd = recv(cli, buff, 100, MSG_DONTWAIT)) > 0)
{
dataReceived = realloc(dataReceived, rcd + temp + 1); // Realloc to fit the size of received data
strcat(dataReceived, buff); // Concat the received buffer to dataReceived
temp = rcd;
packetLength = packetLength + rcd;
memset(buff, 0, 100); // Reinitialize the buffer for the next iteration
}