title: Create char array of integer using digits as size
body: <p>I am trying to create a char array in C, to fill it with the digits of an int, but the int can be of any number of digits.</p>
  
  <p>I'm using a created function called <code>getDigits(int num)</code>, that returns a number of digits the int has.</p>
  
  <pre><code>char buffer[getDigits(number)] = "";
  snprintf(buffer, sizeof(buffer),"%d",number);
  </code></pre>
  
  <p>but when I compile using gcc, it returns:</p>
  
  <p><code>error: variable-sized object may not be initialized</code></p>
  
  <p>I've tried everything. When I declare it as <code>char fileSizeStr[5] = "";</code>, it works. I can see the problem is rising when I try to declare the buffer size dynamically, but I would really like to know if is a way of achieving this.</p>