title: Using calloc() to set up char array, also "freeing" array when done
body: <p>I'm trying to set up an array of strings (in C, using Linux). The array will hold 11 strings (static length). I initially had the array set up as:</p>
  
  <pre><code>char Answers[10][100];
  </code></pre>
  
  <p>but in my code I have a portion that calls fgets(input,sizeof(input),stdin). When this fgets() portion is called, the final element of my Answers array was being overwritten with the value of input (something about Answers' location on the stack?). So now I'm trying to "lock-in" the memory I use for my Answers array. Would I use</p>
  
  <pre><code>char Answers=calloc(11*sizeof(char));
  </code></pre>
  
  <p>OR</p>
  
  <p>Run it through a loop--</p>
  
  <pre><code>char Answers[10];
  for(c=0;c&lt;=10;c++)
  {
      Answers[c]=calloc(1*sizeof(char);
  }
  </code></pre>
  
  <p>Also, I'll need to use atexit() to free the allocated memory when I'm done... What would be the best way to do this since I can't pass arguments inside atexit()?</p>
  
  <p><code>atexit(Free);</code></p>
  
  <pre><code>void Free()
  {
      free(Answers);
  }
  </code></pre>
  
  <p>Thanks in advance!</p>