title: How to change global two dimensional array of structs inside a function on C?
body: <p>I wanted to change a global array using pointers, but it doesn't seem to work. I would appreciate more effective ways to make the job done.</p>
  
  <p>Here is a piece of code, it shows Segmentation fault exception when it reaches a line with <code>-&gt;</code></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  #define MWIDTH  512
  #define MHEIGHT 512
  
  typedef struct
  {
      int artifactValue;
      int artifactType;
      int occupation;
  } sTile;
  
  sTile *tile[MHEIGHT][MWIDTH];
  
  FILE* f;
  int height, width, ii, jj;
  int array[MHEIGHT][MWIDTH];
  
  void getDimensions()
  {
      if ((f = fopen("C:\\C projects\\amazons\\state.txt", "r")) == NULL)
          exit(1);
      if (fscanf(f, "%d%d", &amp;height, &amp;width) != 2)
          exit(1);
      if (height &lt; 1 || height &gt; MHEIGHT || width &lt; 1 || width &gt; MWIDTH)
          exit(1);
  }
  
  void getBoard()
  {
      for(jj=0; jj&lt;height; jj++)
          for(ii=0; ii&lt;width; ii++)
          {
              fscanf(f, "%d", &amp;array[jj][ii]);
  
              if (array[jj][ii] &lt; 10)
              {
                  tile[jj][ii] -&gt; artifactValue = 0;
                  tile[jj][ii] -&gt; artifactType = 0;
                  tile[jj][ii] -&gt; occupation = array[jj][ii];
              }
  
              else if (array[jj][ii] &lt; 100)
              {
                  tile[jj][ii] -&gt; artifactValue = 0;
                  tile[jj][ii] -&gt; artifactType = array[jj][ii] / 10;
                  tile[jj][ii] -&gt; occupation = array[jj][ii] % 10;
              }
  
              else if (array[jj][ii] &lt; 999)
              {
                  tile[jj][ii] -&gt; artifactValue = array[jj][ii] / 100;
                  tile[jj][ii] -&gt; artifactType = array[jj][ii] % 100 / 10;
                  tile[jj][ii] -&gt; occupation = array[jj][ii] % 100 % 10;
              }
          }
  }
  </code></pre>