title: Character array reuse
body: <p>I'm writing a Win32 console application in Visual Studio 2010.</p>
  
  <p>Consider one function that take two <code>char*</code> as parameters.</p>
  
  <p>Following is prototype of function:</p>
  
  <pre><code>void WriteApplicationFile(char *mappname,char* MessageString)
  {
     //Do some File related stuffs.
  }
  </code></pre>
  
  <p>Now the following calls are working perfectly:</p>
  
  <pre><code>WriteApplicationFile("FirstOne", "Append Me");
  WriteApplicationFile("FirstOne", "Append Another");
  </code></pre>
  
  <p>But if I try the same thing with some character array thing this will give me assertion, and throw me on assembly.</p>
  
  <p>The following code is not working:</p>
  
  <pre><code>char * LocalBuffer  = new char[100]; 
  sprintf(LocalBuffer,"Number of jobs in Queue %d",JobsCount);
  WriteApplicationFile("SAAZshadowProtect",LocalBuffer);
  free(LocalBuffer);
  LocalBuffer = NULL;
  //Work fine.
  //...
  LocalBuffer  = new char[100]; 
  sprintf(LocalBuffer,"Log file name %s",LogFileCharName);
  WriteApplicationFile("SAAZshadowProtect",LocalBuffer);
  free(LocalBuffer);   // I got assertion here..
  LocalBuffer = NULL;
  </code></pre>
  
  <p>Where am I going wrong?</p>
  
  <p>One more thing is that I want to handle all assertion and bugs with try-catch block. How would I do this?</p>