title: Allocate memory for a struct with a character pointer in C
body: <p>I was struggling to fix a code today, then I come across something similar to:</p>
  
  <pre><code>typedef struct {
  int a; 
  int b; 
  int c;
  int d;
  char* word;
  } mystruct;
  
  int main(int argc, char **argv){
  
      mystruct* structptr = malloc(sizeof(mystruct));
      if (structptr==NULL) {
          printf("ERROR!")
          ...
      }
      ...
      free(structptr);
  
      return 0;
  }
  </code></pre>
  
  <p>the code was giving lots of memory errors due to the fact, that <code>char* word</code> is a string of variable length, and malloc was not allocating enough memory for it. In fact it was only allocating <code>20 Bytes</code> for the whole <code>struct</code>. Is there a way around this issue, without turning the <code>char*</code> into sth like <code>char word[50]</code>?</p>