title: How to dynamically allocate memory within structs?
body: <p>For this week's assignment in my CS class, we have to revise our current program to dynamically allocate memory for all arrays. We have to ensure that no memory is wasted on empty elements. We have to do this by assignment character arrays to temp arrays, size checking the temp, and then allocating an array of that size.</p>
  
  <p>Anyway, I don't get how to do it with a struct. I know how to dynamically allocate memory, for example</p>
  
  <pre><code>int* pointer = new int(5);
  </code></pre>
  
  <p>But how do I do that for struct members? It seems like unless you define the size up front, the computer wouldn't know how much space to allocate when you declare a struct of that type.</p>
  
  <p>Right now, my struct definition is like so:</p>
  
  <pre><code>struct card
     {
     char rank[10];
     char suit[10];
     char color;
     bool dealt;
     char location[12];
     };
  </code></pre>
  
  <p>How do I change all the arrays to be declared dynamically, without specifying size?</p>