title: Passing pointer to array of struct
body: <p>I'm trying to pass a pointer to an array of struct. This code should create an array of struct, writes to the vars in struct, and then prints them out (which works). Then I want to pass a pointer of that array of struct to another function and print out the array of struts.  </p>
  
  <pre><code>#define PORT_NUMBER 5100
  #define MAX_CLIENTS 5
  
  #include &lt;sys/types.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;arpa/inet.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;string.h&gt;
  #include &lt;pthread.h&gt;
  
  typedef struct thread_args
   {
      int client_number;
      int connected;
      char client_name[1024];
  } client;
  
  void pass_func(client* clients[])
  
  int main()
  {
    struct thread_args clients[MAX_CLIENTS];
    int i;
  
    for(i =0; i &lt; MAX_CLIENTS; i++)
    {
    clients[i].client_number=i;
    strcpy(clients[i].client_name, "BOBBY");
    }
  
      for(i =0; i &lt; MAX_CLIENTS; i++)
    {
       printf("%d | %s\n", clients[i].client_number=i, clients[i].client_name);
    }
  
    printf("\n\n");
    pass_func(&amp;clients);
  }
  
  void pass_func(client* clients[])
  {
    int i;
    for(i =0; i &lt; MAX_CLIENTS; i++)
    {
       printf("%d | %s\n", clients[i]-&gt;client_number=i, clients[i]-&gt;client_name);
    }
  }
  </code></pre>
  
  <p>And this is the output:</p>
  
  <pre><code>$ gcc TEST.c -lpthread -o TEST.out
  TEST.c: In function ‘main’:
  TEST.c:41:3: warning: passing argument 1 of ‘pass_func’ from incompatible pointer type [enabled by default]
  TEST.c:22:6: note: expected ‘struct thread_args **’ but argument is of type ‘struct thread_args (*)[5]’
  
  $ ./TEST.out 
  0 | BOBBY
  1 | BOBBY
  2 | BOBBY
  3 | BOBBY
  4 | BOBBY
  
  
  Segmentation fault
  </code></pre>
  
  <p>I've done about an hour of research and can't figure out why this is not working. Most of the examples I find are for C++, but not C. (And yes I know many of the header files I've included are not necessary for  this code; this is just a segment of my original code.)</p>