title: Code running on debug mode but not on release mode
body: <p>I'm trying to create a simple crossword puzzle game. Which I read a txt file that includes all information about the words(direction, starting position, clues etc.). I tried to debug and my program worked perfectly on debug mode even without any breakpoint. I use Code::Blocks 17.12. and GNU GCC Compiler. I'm a newbie on C so I couldn't figure out why my code doesn't work in release mode.</p>
  
  <p>It crashes when I enter the name of txt file.</p>
  
  <p><em>sorry for long post but I don't know where the mistake is</em></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;unistd.h&gt;
  #define MAX_WORD_LENGTH 10
  #define MAX_CLUES_LENGTH 50
  typedef struct
  {
  char *word;     //word and corresponding hint
  char *clues;
  int x;      //Starting x and y positions
  int y;
  char direction;     //H for horizontal, V for vertical
  int f;      //solved or not
  } Word_t;
  
  Word_t* loadTextFile(FILE* myfile, int nrWords);
  void displayBoard(int rows, int cols, char** myBoard);
  int isBoardFilled(int rows, int cols, char** myBoard);
  char** createArray(int rows, int cols);
  int findIndex(int arr[], int size, int val);
  void playGame(char** myBoard, int words, Word_t *rWords, int x, int y, int 
  countToFinish);
  char** updateBoard(char** myBoard, Word_t *nWords, int solve);
  
  int main()
  {
  FILE *input_file;
  char file_name[20];
  int rows, cols, nrWords, count=0;
  printf("\nEnter name of text file: ");
  gets(file_name);
  while(access( file_name, F_OK) == -1)
  {
      printf("Cannot open the file or file does not exist.\nPlease try again: ");
      gets( file_name);
  }
  input_file = fopen(file_name, "r");
  fscanf(input_file,"%d%d%d", &amp;rows, &amp;cols, &amp;nrWords);
  Word_t* words;
  words=(Word_t*)malloc(sizeof(Word_t)*nrWords);
  for(int i=0; i&lt;nrWords; i++)
  {
      words[i].word = malloc(sizeof(MAX_WORD_LENGTH));
      words[i].clues=malloc(sizeof(MAX_CLUES_LENGTH));
  }
  printf("Game is %d rows x %d cols with %d words\n", rows, cols, nrWords);
  words=loadTextFile(input_file,nrWords);
  char **myBoard=(char**)malloc(rows * sizeof(char *));
  for(int i=0; i&lt;rows; i++)
  {
      myBoard[i]=(char*)malloc(cols * sizeof(char));
  }
  myBoard=createArray(rows,cols);
  /*for(int i=0;i&lt;rows;i++)
  {
      for(int j=0;j&lt;cols;j++)
      {
          printf("%c ", myBoard[i][j]);
      }
      printf("\n");
  }*/
  for(int i=0; i&lt;nrWords; i++)
  {
      myBoard=updateBoard(myBoard, words, -1);
  }
  playGame(myBoard, nrWords, words, rows, cols, nrWords);
  
  fclose(input_file);
  free(words);
  
  return 0;
  }
  Word_t* loadTextFile(FILE* myfile, int nrWords)
  {
  Word_t* temp;
  temp=malloc(sizeof(Word_t)*nrWords);
  for(int count=0; count&lt;nrWords; count++)
  {
      temp[count].word=malloc(MAX_WORD_LENGTH);
      temp[count].clues=malloc(MAX_CLUES_LENGTH);
      fscanf(myfile," %c %d %d %s %[^\n]%*c", &amp;temp[count].direction, &amp;temp[count].x, &amp;temp[count].y, temp[count].word, temp[count].clues);
  }
  printf("Words and clues are read!\n");
  return temp;
  }
  char** createArray(int rows, int cols)
  {
  int count=0;
  char** tempBoard = (char**)malloc(rows * sizeof(char*));
  for(int i=0; i&lt;rows; i++)
  {
      tempBoard[i]=(char*)malloc(cols*sizeof(char*));
  }
  count=0;
  for(int i=0; i&lt;rows; i++)
      for(int j=0; j&lt;cols; j++)
          tempBoard[i][j]='#';
  return tempBoard;
  }
  void displayBoard(int rows, int cols, char** myBoard)
  {
  int i;
  for(i=0; i&lt;cols; i++)
  {
      printf(" %d ", i+1);
  }
  printf("\n     ");
  for(i=0; i&lt;cols; i++)
  {
      printf(" --");
  }
  printf("\n");
  for(i=0; i&lt;rows; i++)
  {
      printf("%d    |", i+1);
      for(int k=0; k&lt;cols; k++)
      {
          printf("%-3c", myBoard[i][k]);
      }
      printf("\n");
  }
  printf("     ***************\n");
  }
  int isBoardFilled(int rows, int cols, char** myBoard)
  {
  for(int i=0; i&lt;rows; i++)
  {
      for(int k=0; k&lt;cols; k++)
      {
          if((myBoard[i][k])=='_')
              return 0;
      }
  }
  return 1;
  }
  int findIndex(int arr[], int size, int val)
  {
  for(int i=0; i&lt;size; i++)
  {
      if(arr[i]==val)
          return 1;
  }
  return 0;
  }
  char** updateBoard(char** myBoard, Word_t *nWords, int solve)
  {
  if(solve==-1)
  {
      for(int k=0; k&lt;sizeof(Word_t); k++)
      {
          if(nWords[k].direction=='V')
          {
              int len=strlen(nWords[k].word);
              for(int i=0; i&lt;len; i++)
              {
                  myBoard[((nWords[k].x)-1)+i][(nWords[k].y)-1]='_';
              }
          }
          else if(nWords[k].direction=='H')
          {
              int len=strlen(nWords[k].word);
              for(int i=0; i&lt;len; i++)
              {
                  myBoard[(nWords[k].x)-1][((nWords[k].y)-1)+i]='_';
              }
          }
      }
  }
  else if(solve!=-1)
  {
      if(nWords[solve].direction=='V')
      {
          int len=strlen(nWords[solve].word);
          for(int i=0; i&lt;len; i++)
          {
              myBoard[((nWords[solve].x)-1)+i][(nWords[solve].y)-1]=nWords[solve].word[i];
          }
      }
      else if(nWords[solve].direction=='H')
      {
          int len=strlen(nWords[solve].word);
          for(int i=0; i&lt;len; i++)
          {
              myBoard[(nWords[solve].x)-1][((nWords[solve].y)-1)+i]=nWords[solve].word[i];
          }
      }
  }
  return myBoard;
  }
  void playGame(char** myBoard, int words, Word_t *rWords, int x, int y, int countToFinish)
  {
  int gameOver=0;
  char answer[MAX_WORD_LENGTH];
  int array[countToFinish];
  int index;
  int filled;
  printf("\nCurrent puzzle:\n\n");
  printf("     ");
  for(int i=0; i&lt;countToFinish; i++)
  {
      myBoard=updateBoard(myBoard, rWords, -1);
  }
  displayBoard(x, y, myBoard);
  while(gameOver&lt;countToFinish || filled != 1)
  {
      printf("\nAsk for hint:\n");
      printf("# Direction     row     col\n");
      printf("------------------------------\n");
      for(int k=0; k&lt;countToFinish; k++)
      {
          if(rWords[k].direction=='H')
          {
              printf("%d: Horizontal    %d    %d\n", k+1, rWords[k].x, rWords[k].y);
          }
          else
          {
              printf("%d: Vertical      %d    %d\n", k+1, rWords[k].x, rWords[k].y);
          }
      }
      printf("\nEnter -1 to exit\n");
      printf("Which word to solve next?: ");
      scanf(" %d", &amp;words);
      if(words == -1)
      {
          return 0;
      }
      while(words&gt;countToFinish || words&lt;=0 )
      {
          printf("Invalid input\n");
          printf("Please try again:");
          scanf("%d", &amp;words);
      }
      index=findIndex(array, countToFinish, words);
      while(index == 1)
      {
          printf("That word has been solved before");
          printf("\nEnter -1 to exit\n");
          printf("Which word to solve next?: ");
          scanf(" %d", &amp;words);
          index=findIndex(array, countToFinish, words);
      }
      printf("\nCurrent hint: %s", rWords[words-1].clues);
      printf("\nEnter your solution: ");
      scanf("%s", &amp;answer);
      if(strcasecmp(answer,rWords[words-1].word)==0)
      {
          printf("\nCorrect!\n");
          gameOver++;
          myBoard=updateBoard(myBoard, rWords, (words-1));
          displayBoard(x, y, myBoard);
          array[words]=words;
      }
      else
      {
          printf("\nWRONG ANSWER\n");
          printf("Current puzzle:\n");
          displayBoard(x, y, myBoard);
      }
      filled = isBoardFilled(x, y, myBoard);
  }
  
  }
  </code></pre>