title: How can I calculate the length of string produced in a varargs function in C?
body: <p>Suppose I have a call to <code>printf</code> that will print the name of a file whose length can only be determinate at runtime:</p>
  
  <pre><code>//"buff" gets the name of the file
  printf("Name of the file is: %s",buff);
  </code></pre>
  
  <p>What I would like to know is how can I calculate the length of the final string. In my example above, if the name of the file is "file.txt", this value would be 29. I need this because I need to create a buffer whose size shall match the length of the string it's going to get and this inside a function that uses varargs:</p>
  
  <pre><code>void general_printfL(__const char *__restrict __format, ...)
  {
      char buffy[final_size_of__format];
  
      //Do something...
  }
  </code></pre>
  
  <p>I tried using <code>sizeof(char) * strlen(__format)</code> for the code above, but the segmentation faults I got indicated me this isn't an appropriate way of calculating the final string's length. I also couldn't find anything useful on Google about this.</p>