title: Segmentation error trying to implement flood fill
body: <p>I'm trying to implement flood fill algorithm for 2d array of characters.</p>
  
  <p>The problem is when i try to run it i get a segmentation error. 
  I tried multiple things but i cant figure out whats the problem. </p>
  
  <p>I'm trying with this input: <a href="http://pastebin.com/raw/puexQfXY" rel="nofollow noreferrer">http://pastebin.com/raw/puexQfXY</a></p>
  
  <p>Screenshot of error: <a href="https://gyazo.com/b7e738d1d4f09a5d71a020b34a1e3b6c" rel="nofollow noreferrer">https://gyazo.com/b7e738d1d4f09a5d71a020b34a1e3b6c</a></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  void floodFill(int width, int height, char grid[width][height], char replacement, char target, int x, int y)
  {
      if(x &lt; 0 || x &gt;= width || y &lt; 0 || y &gt;= height)
      {//check if out of array
          return;
      }
      if(grid[x][y] != target)
      {//check if on other than the target
          return;
      }
      grid[x][y] = replacement; //replace
      floodFill(grid, width, height, replacement, target, x + 1, y);//right
      floodFill(grid, width, height, replacement, target, x, y + 1);//down
      floodFill(grid, width, height, replacement, target, x - 1, y);//left
      floodFill(grid, width, height, replacement, target, x, y - 1);//up
  
  }
  
  int main()
  {
      int width, height;
      scanf("%d", &amp;width);
      scanf("%d", &amp;height);
      char grid[width][height];
      for(int y = 0; y &lt; height; y++)
      {
          getchar();//absorb newline
          for(int x = 0; x &lt; width; x++)
          {
              grid[x][y] = getchar();
          }
      }
  
      floodFill(width, height, grid, 'O', '.', 2, 1);
      for(int y = 0; y &lt; height; y++)
      {//print array
          for(int x = 0; x &lt; width; x++)
          {
              putchar(grid[x][y]);
          }
          putchar('\n');
      }
  }
  </code></pre>