I receive a char * buffer which have the lenght of 10. But I want to concat the whole content in my struct which have an variable char *.
typedef struct{
I am not clear. Do you want:
real[0].buffer, or real[i].buffer, or You will need to allocate enough space for the copy of the buffer:
#include
//...
int size = 10+1; // need to allocate enough space for a terminating '\0'
char* buff = (char *)malloc(size);
if (buff == NULL) {
fprintf(stderr, "Error: Failed to allocate %d bytes in file: %s, line %d\n,
size, __FILE__, __LINE__ );
exit(1);
}
buff[0] = '\0'; // terminate the string so that strcat can work, if needed
//...
real[i].buffer = buff; // now buffer points at some space
//...
strncpy(real[i].buffer, buffer, size-1);