title: C format string when writing to file
body: <p>I'm having a bit of noob confusion how to use a formated string when writing to a file, and more in general I guess about <code>sprintf</code>. </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main(int argc, char* argv[]) 
  {
      FILE *fp;
      const char *exts = ".txt";
      char *saveToPath;
  
      sprintf(saveToPath, "/Path/To/My/File%s", exts);
  
      fp = fopen(saveToPath, "w+");
      fprintf(fp, "This is testing for fprintf...\n");
      fputs("This is testing for fputs...\n", fp);
      fclose(fp);
  }
  </code></pre>
  
  <p>I get a <code>segmentation fault</code> when trying the formatted saveToPath, but if I use a plain string <code>const char*</code> like "/Path/To/My/File.txt" it works.</p>