title: Dynamic Memory Allocation in C++ structs
body: <p>I don't understand the syntax required for dynamically allocating members of a struct in c++. Basically, I need to fill char array members to exact size using a temp array and strlen. Here is my struct:</p>
  
  <pre><code>struct card
     {
     char *rank;
     char *suit;
     char color;
     bool dealt;
     char *location;
     };
  </code></pre>
  
  <p>Here is the function that uses the struct:</p>
  
  <pre><code>bool importCard(card *deckPtr, char *deckName);
  </code></pre>
  
  <p>I created an array of 52 cards and assigned a pointer to it, and passed it to the function as the first parameter. (deckPtr) Here is a loop in the function that is supposed to read in card info to the struct data members.</p>
  
  <pre><code>for(index=0;index&lt;52;index++,deckPtr++)
    {
  
    fin &gt;&gt; *temp;
    charCount=stringLength(temp);
    deckPtr.*rank = new char[charCount+1];
    stringCopy(*temp, deckPtr.*rank);
  
    fin &gt;&gt; *temp;
    charCount=stringLength(temp);
    deckPtr.*suit = new char[charCount+1];
    stringCopy(*temp, deckPtr.*suit);
  
    if(deckPtr.*suit==('d')||deckPtr.*suit==('h'))
       {
       (*deckPtr).color='r';
       }
    else
       {
       (*deckPtr).color='b';
       }
  
    (*deckPtr).dealt=false;
  
    deckPtr.*location = new char[11];
    stringCopy(unshPtr, deckPtr.*location);
  
    }
  </code></pre>
  
  <p>I am getting three compile errors: "rank" "suit" and "location" are "not declared in this scope." What am I doing wrong? Thanks!</p>