Q:

Concatenate strings and store them in a buffer in ANSI C

I have a function that calls OutputBuffer serveral times:
void display(void)
{
    OutputBuffer("This is String One");
    sprintf(PrintBuffer, "String Two %s",modeStr);
    OutputBuffer(PrintBuffer);
    sprintf(PrintBuffer,"AddString = %s",modeStr2);
    OutputBuffer(PrintBuffer);
}

In OutputBuffer i'd like to store the strings in a global variable char TestBuffer[1000] and later on show them on a display:
void OutPutBuffer(char *Buffer)
{
    int var = strlen(Buffer);
    sprintf(TestBuffer, Buffer);
}

I only get the length of each String but but only the last string (AddString ...). Any suggestions how to solve this?

A:

Using strcat
void OutputBuffer(char *Buffer)
{
     int var = strlen(Buffer);

     if(var+strlen(TestBuffer)>=1000)
       return;

    strcat(TestBuffer,Buffer);
}

Using snprintf
void OutPutBuffer(char *Buffer)
{
    int var = strlen(Buffer);

     if(var+strlen(TestBuffer)>=1000)
           return;

    snprintf(TestBuffer+strlen(TestBuffer),var,"%s",Buffer);
}

