title: In C : how to pass an array of structures as a pointer
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2360794/how-to-pass-an-array-of-struct-using-pointer-in-c-c">How to pass an array of struct using pointer in c/c++?</a>  </p>
  </blockquote>
  
  
  
  <p>I have an array of structures and need to pass a pointer to the array to a function.</p>
  
  <p>I get these compile warnings and it crashes at runtime:</p>
  
  <blockquote>
    <p>test.c:35:5: warning: passing argument 1 of ‘displayArray’ from incompatible pointer type<br>
    test.c:20:6: note: expected <code>‘struct tagdata **’</code> but argument is of type <code>‘struct tagdata (*)[10]’</code></p>
  </blockquote>
  
  <pre><code>typedef struct tagdata{
      char lastName[20];
      char firstName[20];
      int age;
  } PERSON[10], *PPERSON[];
  
  int genNumber();
  void displayArray(PPERSON pPerson);
  
  int main(){
      PERSON personDetails;
      int i;
      char buf[20];
  
      for (i = 0; i &lt; 10; i++){
          sprintf(buf, "Charlie%d", i);
          strcpy(personDetails[i].firstName, buf);
          sprintf(buf, "Brown - %d", i);
          strcpy(personDetails[i].lastName, buf);
          personDetails[i].age = genNumber();
      }
  
      displayArray(&amp;personDetails);
  
      exit(0);
  }
  void displayArray(PPERSON pPerson){
      int i = 0;
  
      while (i &lt; 10){
          printf("Last Name   First Name  Age\n");
          printf("%s          %s          %d\n",
                 pPerson[i]-&gt;lastName,
                 pPerson[i]-&gt;lastName,
                 pPerson[i]-&gt;age);
          i++;
      }
  }
  int genNumber(){
      int n;
      n=random();
  
      return(n);
  }
  </code></pre>