title: My program gives segmentation fault in openSUSE
body: <p>I have a laptop in which I've installed openSUSE 13.2 a month ago. When I try to run this C++ program to print shortest path, I get a segmentation fault. On the other hand, my code works perfectly on my computer on which Ubuntu is installed.</p>
  
  <p>Here is the output I get in Ubuntu...</p>
  
  <pre><code>rohan@Symantha:~/Dropbox/cprog/Arrayss/2D$ uname -a
  Linux Symantha 3.13.0-53-generic #89-Ubuntu SMP Wed May 20 10:34:28 UTC 2015 i686 i686 i686 GNU/Linux
  rohan@Symantha:~/Dropbox/cprog/Arrayss/2D$ g++ 16.cpp 
  rohan@Symantha:~/Dropbox/cprog/Arrayss/2D$ ./a.out 
  Enter total rows : 4
  Enter total cols : 4
  Enter array -&gt;
  1 0 0 0
  1 1 1 0
  0 1 1 0
  1 1 1 1
  Input Ok ..
  Enter source row: 0
  Enter source col: 0
  Enter destination row: 3
  Enter destination col: 3
  Shortest Path --&gt;&gt;
  path :  (0, 0) -&gt;  (1, 0) -&gt;  (1, 1) -&gt;  (1, 2) -&gt;  (2, 2) -&gt;  (3, 2) -&gt;  (3, 3) 
  </code></pre>
  
  <p>But in openSUSE, I get this...</p>
  
  <pre><code>rohan@linux-zdor:~/Dropbox/cprog/Arrayss/2D&gt; uname -a
  Linux linux-zdor.site 3.16.7-21-desktop #1 SMP PREEMPT Tue Apr 14 07:11:37 UTC 2015 (93c1539) x86_64 x86_64 x86_64 GNU/Linux
  rohan@linux-zdor:~/Dropbox/cprog/Arrayss/2D&gt; g++ 16.cpp 
  rohan@linux-zdor:~/Dropbox/cprog/Arrayss/2D&gt; ./a.out 
  Enter total rows : 4
  Enter total cols : 4
  Enter array -&gt;
  1 0 0 0
  1 1 1 0
  0 1 1 0
  1 1 1 1
  Input Ok ..
  Enter source row: 0
  Enter source col: 0
  Enter destination row: 3
  Enter destination col: 3
  Shortest Path --&gt;&gt;
  Segmentation fault
  </code></pre>
  
  <p>Can anyone tell me what is wrong with my code?
  Here is my code:</p>
  
  <p><a href="https://drive.google.com/file/d/0BzLbrlYg9GyXd3E4WnFWc3lGVUk/view?usp=sharing" rel="nofollow">https://drive.google.com/file/d/0BzLbrlYg9GyXd3E4WnFWc3lGVUk/view?usp=sharing</a></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;unistd.h&gt;
  using namespace std;
  
  #define MAXROW 10
  #define MAXCOL 10
  
  class Cell {
  public:
    int row;
    int col;
    Cell() { }
    Cell(int rr, int cc) : row(rr), col(cc) { }
    bool operator==(const Cell&amp; cc) {
      if(row == cc.row &amp;&amp; col == cc.col)
        return true;
      else 
        return false;
    }
  };
  
  class Path {
    int row[MAXROW*MAXROW];
    int col[MAXCOL*MAXCOL];
    int size;
  public:
    Path() : size(0) { }
    Path(Path&amp; pp) {
      size = pp.size;
      for(int i = 0; i &lt; size; i++) {
        row[i] = pp.row[i];
        col[i] = pp.col[i];
      }
    }
    Path&amp; operator=(const Path&amp; pp) {
      size = pp.size;
      for(int i = 0; i &lt; size; i++) {
        row[i] = pp.row[i];
        col[i] = pp.col[i];
      }
    }
    int length() {
      return size;
    }
    void setSize(int ss) {
      size = ss;
    }
    void insert(int rr, int cc) {
      row[size] = rr;
      col[size] = cc;
      size++;
    }
    void print() {
      int i = 0;
      cout &lt;&lt; "path : ";
      while(i &lt; size) {
        cout &lt;&lt; " (" &lt;&lt; row[i] &lt;&lt; ", "
             &lt;&lt; col[i] &lt;&lt; ") ";
        if(i &lt; size-1)
          cout &lt;&lt; "-&gt; ";
        i++;
      }
      cout &lt;&lt; endl;
    }
    bool searchCell(Cell c) {
      int i = 0;
      while(i &lt; size) {  
        if(row[i] == c.row &amp;&amp; col[i] == c.col)
          return true;
        i++;
      }
      return false;
    }
    Cell start() {
      return Cell(row[0], col[0]);
    }
    Cell end() {
      if(size &gt; 0)
        return Cell(row[size-1], col[size-1]);
      else
        return Cell(-1, -1);
    }
  };
  
  
  Path shortestPath(int arr[][MAXCOL], int, int, Cell, Cell, Path);
  void inputArr(int arr[][MAXCOL], int mR, int mC);
  
  
  int main() {
    int arr[10][10], mR, mC, r, c;
    Path p;
    cout &lt;&lt; "Enter total rows : ";
    cin &gt;&gt; mR;
    cout &lt;&lt; "Enter total cols : ";
    cin &gt;&gt; mC;
    cout &lt;&lt; "Enter array -&gt;\n";
    inputArr(arr, mR, mC);
    cout &lt;&lt; "Input Ok ..\n";
    cout &lt;&lt; "Enter source row: ";
    cin &gt;&gt; r;
    cout &lt;&lt; "Enter source col: ";
    cin &gt;&gt; c;
    Cell source(r, c);
    cout &lt;&lt; "Enter destination row: ";
    cin &gt;&gt; r;
    cout &lt;&lt; "Enter destination col: ";
    cin &gt;&gt; c;
    Cell destination(r, c);
    cout &lt;&lt; "Shortest Path --&gt;&gt;\n";
    p = shortestPath(arr, mR, mC, source, destination, p);  
    p.print();
    return 0;
  }
  
  Path shortestPath(int arr[][MAXCOL], int mR, int mC, Cell current, Cell target, Path p) {
    int i = current.row;
    int j = current.col;
    Path p_array[4];
    if(arr[i][j] == 0 || i == mR || j == mC || i &lt; 0 || j &lt; 0 
       || p.searchCell(current)) {
      p.setSize(0);
      return p;
    }
    p.insert(i, j);
    if(i == target.row  &amp;&amp;  j == target.col) 
      return p;  
    else {
      // Since there are four possible directions
      p_array[0] = shortestPath(arr, mR, mC, Cell(i, j+1), target, p);
      p_array[1] = shortestPath(arr, mR, mC, Cell(i+1, j), target, p);
      p_array[2] = shortestPath(arr, mR, mC, Cell(i, j-1), target, p);
      p_array[3] = shortestPath(arr, mR, mC, Cell(i-1, j), target, p);
      int minIndex, minSize, i;
      for(i = 0; i &lt; 4; i++) {
        if(p_array[i].length() != 0 &amp;&amp; p_array[i].end() == target ) {
          minIndex = i;
          minSize = p_array[i].length();
          break;
        }
      }    
      for(i = 0; i &lt; 4; i++) {
        if(p_array[i].length() &lt; minSize &amp;&amp; p_array[i].end() == target) {
          minIndex = i;
          minSize = p_array[i].length();
        }
      }
      return p_array[minIndex];
    }
  }
  
  void inputArr(int arr[][MAXCOL], int mR, int mC) {
    int i, j;
    for(i = 0; i &lt; mR; i++)
      for(j = 0; j &lt; mC; j++)
        cin &gt;&gt; arr[i][j];
  }
  </code></pre>