title: C - initialize array of structs
body: <p>I am having a problem initializing an array of structs. I'm not sure if I am doing it right because I get "initialization from incompatible pointer type" &amp; "assignment from incompatible pointer type". I added in the code where I get these warnings, and when I try to print the data from the struct I just get garbage such as @@###</p>
  
  <pre><code>typedef struct
  {
      char* firstName;
      char* lastName;
      int day;
      int month;
      int year;
  
  }student;
  </code></pre>
  
  <p>//initialize array</p>
  
  <pre><code>    student** students = malloc(sizeof(student));
      int x;
      for(x = 0; x &lt; numStudents; x++)
      {
          //here I get: "assignment from incompatible pointer type" 
          students[x] = (struct student*)malloc(sizeof(student));
      }
  
      int arrayIndex = 0;
  </code></pre>
  
  <p>//add struct</p>
  
  <pre><code> //create student struct
          //here I get: "initialization from incompatible pointer type"
          student* newStudent = {"john", "smith", 1, 12, 1983};
  
          //add it to the array
          students[arrayIndex] = newStudent;
          arrayIndex++;
  </code></pre>