I am developing a program in Contiki OS .I attempt to copy an input of a function to a char array and then concatenate a dynamic char array to another. The destination return NULL value. here is the code of generating log value which is the input of makerequest function:
char *log;
log = (char *)malloc(400);
if(uip_newdata()) {
strncat(log, (char *)uip_appdata ,uip_datalen());
}
makerequest(log);
and in makerequest function I tried to concatenate the req value to rcvReq :
static char * rcvReq;
void makerequest(char * log){
rcvReq = (char*)malloc(300);
char * req;
req = (char*)malloc(200);
memset(req, 0, sizeof(req));
strcpy(req, log);
...
if(rcvReq != NULL){
strncat(rcvReq, req, strlen(req));
}
else{
strncpy(rcvReq, req, strlen(req));
}
}
req is a temp array to store log value. I expected that req value copied to rcvReq, but value of rcvReq is NULL. I would be really appreciate if you tell me how I can fix the problem.