title: C - How to pass struct pointer array to a function by reference
body: <p>I have this struct:</p>
  
  <pre><code>typedef struct {
      char name[31];
      int played;
      int won;
      int lost;
      int tie;
      int points;
  } Player;
  </code></pre>
  
  <p>And this function which fill the struct array with data from file:</p>
  
  <pre><code>int load(Player *players[], int max_players, int *player_count)
  {
      static const char filename[] = "players.txt";
      FILE *file = fopen(filename, "r");
  
      if (file != NULL)
      {
          char line[128]; 
  
          players = malloc(max_players * sizeof *players);
  
          while (1) /* read until end of file */
          {
  
              players[*player_count] = malloc(sizeof(Player));
  
              if (*player_count &lt; max_players &amp;&amp; fgets(players[*player_count]-&gt;name, sizeof players[*player_count]-&gt;name, file) != NULL)
              {
                  fscanf(file, "%d", &amp;players[*player_count]-&gt;played);    // read played
                  fscanf(file, "%d", &amp;players[*player_count]-&gt;won);       // read won 
                  fscanf(file, "%d", &amp;players[*player_count]-&gt;lost);      // read lost 
                  fscanf(file, "%d", &amp;players[*player_count]-&gt;tie);       // read tie 
                  fscanf(file, "%d", &amp;players[*player_count]-&gt;points);    // read points 
                  fgets(line, sizeof line, file);                         // read new line
  
                  // increase player count
                  *player_count += 1;
              }
              else
              {
                  break;
              }
          }
  
          fclose(file);
      }
      else
      {
          return 0;
      }
      return 1;
  }
  </code></pre>
  
  <p>Now I am having a problem with calling it by passing players as a reference so that the updated data of players gets reflected at the calling end.</p>
  
  <p>Below is my calling code, which I think has the problem:</p>
  
  <pre><code>Player *players[MAX_PLAYERS] = { NULL };
  int playerCount = 0;
  load(players, MAX_PLAYERS, &amp;playerCount);
  </code></pre>
  
  <p>When I debug the code, the players' array gets filled in the function but when it returns back, the players' value is still null.</p>
  
  <p>Any help would be appreciated.</p>