title: C: dynamic allocation during a scanf
body: <p>I would like to know if there is any way to dynamically allocate some memory when/before using a scanf. This would mean that there is no need to give a <code>char *</code> a size when initializing it. Instead of this, the quantity of memory needed would be allocated depending on the size of the input string (which means: after having the input).</p>
  
  <p>Currently I find no other solution than to allocate a specific quantity of memory before having the input, so before knowing the size of the input:</p>
  
  <pre><code>char str[10];
  scanf("%s", str);
  </code></pre>
  
  <p>And I know this is not safe: if the input is longer than 10 characters, the program will write on unallocated memory, which can cause segfaults or stuff like that.</p>