From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

C question dealing with strcat and pointers

I am having trouble trying to build a global buffer between TCP_DATAREADY callbacks. I have attached the code for the callback. Here are the lines that are giving me trouble.


strcat(ptrMem->pszScript,&szBuffer[12]);
printf(ptrMem->pszScript);

It seems that each strcat is working like a strcpy and eradicating the previous value of the strcat. The linked list is declared globally. The pointer to the particular node I am dealing with is re-found each time I get a new buffer in with TCP_DATAREADY. When it is all done, and I try printing with printf(ptrMem->pszScript), I only print the last buffer, not the accumulated buffers. Please help. I am out of ideas.
0 Kudos
Message 1 of 3
(2,875 Views)
I modifed the pszScript to be a static varaible instead of being malloc'd and now it works fine.
0 Kudos
Message 2 of 3
(2,875 Views)
Just a reminder: The concatanated (resultant) string is overwritten on the second argument to the strcat function.
0 Kudos
Message 3 of 3
(2,875 Views)