title: va_list and char* strings
body: <p><strong>[EDIT]</strong> inserted NULL terminated in samples</p>
  
  <p>I have a function that receives a <code>va_list</code> which ends with a <code>NULL</code>. I concatenate each string in a <code>char*</code> called <code>joinedString</code>. Function works as expected except by my <code>joinedString</code> grows its size each time I call this function. I mean the previous string remains and new string is joined.</p>
  
  <p>Example:
  First call:</p>
  
  <pre><code>ShowMsg(style1, "a", "s", "d", NULL);
  </code></pre>
  
  <p>Yielded result: "asd"</p>
  
  <p>Second call:</p>
  
  <pre><code>ShowMsg(style1, "w", "w", "q", NULL);
  </code></pre>
  
  <p>Yielded result: "asdwwq"</p>
  
  <p>This behaviour is strange because each time this function is called <code>joinedString</code> is initialized. Does va_list holds values previously used?
  I'm using C, not C++ and I know, using std::string will be far more easy.</p>
  
  <pre><code>int ShowMsg(MSGBOXSTYLE msgStyle, char* str, ...)
  {
      char* title = "", *joinedString = "", *theArg = "";
      wchar_t* convertedTitle = "", *convertedString = "";
  
      va_list args;
      theArg = str;
      va_start( args, str );
          while(theArg != NULL)
          {
              if(msgStyle == WARN)
              {
                  title = theArg;
              }
              else
              {
                  strcat( joinedString, theArg );
                  strcat( joinedString, "\n\r" );
              }
              theArg = va_arg(args, char*);
          }
      va_end(args);
      ...
      convertedTitle = (wchar_t*)malloc((strlen(title)+1)*sizeof(wchar_t));
      convertedString = (wchar_t*)malloc((strlen(joinedString)+1)*sizeof(wchar_t));
      mbstowcs( convertedTitle, title, strlen(title)+1 );
      mbstowcs( convertedString, joinedString, strlen(joinedString)+1 );
      ...
      free(convertedTitle);
      free(convertedString);
  }
  </code></pre>