title: Malloc an array inside a struct
body: <p>I'm trying to <code>malloc</code> an array inside a struct but I keep getting segmentation errors when I run the program.</p>
  
  <p>The <code>compares</code> function is just something I'm testing so it shouldn't be a part of the problem</p>
  
  <pre><code>typedef struct {
      char *string;
  } prod_t;
  
  int
  main(int agrc, char **argv){
      int i = 0;
      prod_t *c = NULL;
  
      char str2[100] = "abcd";
      c-&gt;string = (char *) malloc( 5 * sizeof(char));
      strcpy(c-&gt;string,str2);
  
      compares(c-&gt;stock,str2,i);
  
      return 0;
  }
  </code></pre>