title: Different output in Windows and Linux (gcc) C compilers
body: <p>I have a program which solves maze, so that it finds possible route from Start(S) to Exit(E).Here is my Maze:</p>
  
  <pre><code>1111S11110
  0000010001
  110100010d
  t001111110
  0100000001
  0111111101
  1111111101
  00000D01T1
  0111110001
  0000E01110
  </code></pre>
  
  <p>The possible route to it is :</p>
  
  <pre><code>Start  S  W  W  S  S  S  E  E  E  E  E  E  S  S  S  S  W  W  N  W  W  W  W  W  W  S  S  E  E  E  E   Exit
  </code></pre>
  
  <p>which is correct and i get it on CodeBlocks, However when i compile my code on dev through putty i get this:</p>
  
  <pre><code>Start  S  S  S  S  S  W  N  N  W  S  W  N  N  N  W  N   Exit
  </code></pre>
  
  <p>Here is my whole code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;ctype.h&gt;
  
  
  // Global Variables for use
  int matrixSize,startX,startY,exitX,exitY;
  char src[1500] = " ";
  char Ndirection[50] = " N ";
  char Sdirection[50] = " S ";
  char Edirection[50] = " E ";
  char Wdirection[50] = " W ";
  
  // Function for finding the array length
  int numOfLines(FILE *const mazeFile) {
    int c, count;
    count = 0;
    for (;; ) {
      c = fgetc(mazeFile);
      if (c == EOF)
        break;
  
      if (c == '\n')
        ++count;        // end of line =&gt; increment line counter
    }
    rewind(mazeFile);
  
    return count+1;
  }
  
  int capLetter(char ch){
     int result = 0;
     if(ch &gt;= 'A' &amp;&amp; ch &lt;= 'Z'){
          result = 1;
     }
     return result;
  }
  
  int lowLetter(char ch){
     int result = 0;
     if(ch &gt;= 'a' &amp;&amp; ch &lt;= 'z'){
          result = 1;
     }
     return result;
  }
  
  int isSafe(char Mazearray[matrixSize][matrixSize],int x,int y){
      if(x &gt;= 0 &amp;&amp; x &lt; matrixSize &amp;&amp; y &gt;= 0 &amp;&amp; y &lt; matrixSize &amp;&amp; Mazearray[x][y] != '1'){
          return 1;
      }
      return 0;
  
  
  }
  
  void MazeSolution(char Mazearray[matrixSize][matrixSize],int x,int y,char pathArray[matrixSize][matrixSize],char wasHereArray[matrixSize][matrixSize]){
      if(recursiveMaze(Mazearray,x,y,pathArray,wasHereArray) == 0){
          printf("There does not exist a possible solution!!!");
      }
      else{
          pathArray[startX][startY] = 'S';
      }
  }
  
  int recursiveMaze(char Mazearray[matrixSize][matrixSize],int x,int y,char pathArray[matrixSize][matrixSize],char wasHereArray[matrixSize][matrixSize]){
      if(x == startX &amp;&amp; y == startY){
          pathArray[x][y] = 'S';
      }
      if(x == exitX &amp;&amp; y == exitY){
          pathArray[x][y] = 'E';
          return 1;
      }
      // check if the coordinate is safe to go(not 1)
      if(isSafe(Mazearray,x,y) == 1 &amp;&amp; wasHereArray[x][y] != '1'){
          wasHereArray[x][y] = '1';
  
          // Move North
          if(recursiveMaze(Mazearray,x-1,y,pathArray,wasHereArray) == 1){
              pathArray[x][y] = 'R';
              strcat(src,Ndirection);
              return 1;
          }
          // Move South
          if(recursiveMaze(Mazearray,x+1,y,pathArray,wasHereArray) == 1){
              pathArray[x][y] = 'R';
              strcat(src,Sdirection);
              return 1;
          }
          // Move East
          if(recursiveMaze(Mazearray,x,y+1,pathArray,wasHereArray) == 1){
              pathArray[x][y] = 'R';
              strcat(src,Edirection);
              return 1;
          }
          // Move West
          if(recursiveMaze(Mazearray,x,y-1,pathArray,wasHereArray) == 1){
              pathArray[x][y] = 'R';
              strcat(src,Wdirection);
              return 1;
          }
      }
      return 0;
  }
  
  // Main Function
  int main( int argc, char **argv )
  {
      // Opening the Matrix File
      FILE *mazeFile;
      mazeFile = fopen(argv[1], "r" );
      if( mazeFile == NULL )
          return 1;
      matrixSize = numOfLines( mazeFile );
      // Reading text file into 2D array
      int i,j;
      char mazeArray [matrixSize][matrixSize];
  
      for (i = 0; i&lt;matrixSize; i++) {
          for (j = 0; j&lt;matrixSize; j++) {
              fscanf(mazeFile, "%c", &amp;mazeArray[i][j]);
          }
  
          char eol;
          fscanf(mazeFile, "%c", &amp;eol);
      }
      // Variables
  
      //Creating path array
      char pathArray[matrixSize][matrixSize];
      for (i = 0; i &lt; matrixSize; i++){
         for (j = 0; j &lt; matrixSize; j++){
              pathArray[i][j] = '0';
          }
      }
      // CheckPoint array
      char wasHereArray[matrixSize][matrixSize];
      for (i = 0; i &lt; matrixSize; i++){
         for (j = 0; j &lt; matrixSize; j++){
              wasHereArray[i][j] = '0';
          }
      }
      // Finding start and exit indexes
      for (i = 0; i&lt;matrixSize; i++) {
        for (j = 0; j&lt;matrixSize; j++) {
          if(mazeArray[i][j] == 'S'){
              startX = i;
              startY = j;
          }
          if(mazeArray[i][j] == 'E'){
              exitX = i;
              exitY = j;
          }
        }
      }
  
      MazeSolution(mazeArray,startX,startY,pathArray,wasHereArray);
      char *data = src;
      int length=strlen(data);
      char bytes[length];
      int n=0;
      while(n&lt;=length)
      {
         bytes[n] = data[length-n-1];
         n++;
      }
  
      FILE *f = fopen("path.txt", "w");
      fprintf(f, "Start %s Exit",bytes);
      fclose(mazeFile);
      fclose(f);
      return 0;
  }
  </code></pre>
  
  <p>I don't know what is wrong and where to start?</p>