title: using calloc on an array of struct, in a function
body: <p>This is my struc</p>
  
  <pre><code>//global
  typedef struct {
      char idCode[MATLENGTH + 10];
      char *name;
  } stud;
  </code></pre>
  
  <p>In main, I do this</p>
  
  <pre><code>Int main() {
  
      stud *students;
      createStudentArray(students);
      ....
  </code></pre>
  
  <p>What I'm trying to do, is:</p>
  
  <p>-pass the array (*student) to a function</p>
  
  <p>-make the function alloc. the array</p>
  
  <p>This is the function i wrote</p>
  
  <pre><code>createStudentArray(stud *students) {
  
      //I get this value from a file
      int nstud = 3;
      students calloc(nstud, sizeof(students));
      return;
  }
  </code></pre>
  
  <p>the problem is:</p>
  
  <p>-when I try to assign any value to a students field, it doesn't work</p>
  
  <p>ex. </p>
  
  <pre><code>Int main() {
  
      stud *students;
      createStudentArray(students);
      ....
      strcpy(students[0].name, "Nicola"); //this is where i get the error
  </code></pre>
  
  <p>My guess is that, in some way, I'm not allocating the array correctly, because, when i try to do </p>
  
  <pre><code>strcpy(students[0].name, "Nicola");
  </code></pre>
  
  <p>in the createStudentArray function, it wortks just fine. So it looks like I am passing the array by value, and not by reference.</p>
  
  <p>Thanks in advance for your help.</p>