This is modem program but it is actually a simple C question so I will post it here.

So I have a modem. I code a buffer and everytime I input a serial string (GPZDG,POS_GPS,DD,MM,YYYY,AA.BB,V*CS), the buffer will be appended like this:
Code:
$GPZDG,POS_GPS,DD,MM,YYYY,AA.BB,V*CS
$GPZDG,POS_GPS,DD,MM,YYYY,AA.BB,V*CS
$GPZDG,POS_GPS,DD,MM,YYYY,AA.BB,V*CS
.
.
My code:

Code:
buffer = memGet( 2000 * sizeof(ascii) ); 
strcat ( ( ascii * ) buffer, ( ascii * ) Data); 
strcat ( ( ascii * ) buffer, ( ascii * )"\x00");
But everytime I appended a fourth string, the program crashes!

So the modem forum adviced me:
"As I told you before, all 'C' string functions rely upon there being a NUL termination - and 'Data' does not have a NUL termination! Therefore this line of code will cause the processor to "run off the end" of your valid data - which will cause your application to crash! You need to make use of the 'Length' parameter to ensure that you don't "run off the end" of 'Data'. Note also that you must not attempt to add a NUL directly at the end of 'Data', because it is just a pointer to some buffer that was allocated by some other part of the system - you cannot assume that it left room for you to add a NUL there! If you want to add a NUL and use it as a 'C' string, you will need to use something like memcpy to copy the data to your own local buffer - and add the NUL there. Again, this is standard 'C' stuff - nothing specific to Wavecom."

So I tried this:
Code:
wm_memcpy ( ( ascii * ) tempBuffer, ( ascii * ) Data, Length );
wm_strcat ( ( ascii * ) buffer, ( ascii * ) tempBuffer);
Didn't work, always crash after the 4 string append, I tried this:
Code:
wm_memcpy ( ( ascii * ) tempBuffer, ( ascii * ) Data, Length );
wm_strcat ( ( ascii * ) buffer, ( ascii * ) tempBuffer); 
wm_strcat ( ( ascii * ) buffer, "\x00")
Didn't work.



Did I missed something? Advance thanks!