title: Trouble printing a 2D char array in C while using fscanf
body: <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;ctype.h&gt;
  
  #define N 5
  
  void readBoard (FILE *fp, char table[N][N], int n){
    int i, err, j, counter = 0;
    char c;
    int row = 0, col = 0, ch = 0;
  
    while((err = fscanf(fp, "%c", &amp;c)) == 1){
  
      if (c!= ' ' &amp;&amp; (c == 'o' || c == 'M' || c == '.')){
        ch++;
        counter++;
  
        if (counter == 5){
         counter = 0;
          row++;
        }
  
      }
  
       if( c != ' ' &amp;&amp; c != 'M' &amp;&amp;  c != 'o' &amp;&amp; c!= '.' &amp;&amp; c != '\n'){
        printf("Error. File is not correct. \n");
        exit(EXIT_FAILURE);
       }
  
    }
  
    col = ch/row;
  
   if (col != N || row != N){
      printf("Error. Incorrect data in file. \n");
      exit(EXIT_FAILURE);
   }
  
  
    i = 0;
    j = 0;
    while((err = fscanf(fp, "%c", &amp;c)) == 1){
  
      if( c!= ' ' &amp;&amp;  (c == 'o' || c == 'M' || c == '.')){
  
        table[i][j] = c;
        j++;
  
       if(j == N-1){
         j = 0;
         i++;
      }
  
     }
  
    }
  
  }
  
  
  
  void displayBoard (char table[N][N]){
  
    int r = 0;
    int c = 0;
    char ch;
  
  
  for(r = 0; r&lt;N; r++){
    for(c = 0; c&lt;N; c++){
      printf("%c ", table[r][c]);
    }
    printf("\n");
   }
  }
  int main(char argc, char *argv[]){
  
   char game[N][N];
   char err, c;
  
   FILE *fp;
   fp = fopen(argv[1], "r");
  
   if(fp == NULL){
     printf("File not found.");
     exit(EXIT_FAILURE);
   }
  
   readBoard(fp, game, N);
   displayBoard(game);
  
  
   return 0;
  </code></pre>
  
  <p>}</p>
  
  <p>The first function reads characters from a file checks if they are correct and stores them into a 2D array.
  The second array is used to print the array. Instead of printing the array it prints this:</p>
  
  <pre><code>� � � 2
     0
  
  @    
  
      p 
  </code></pre>
  
  <p>I have no idea what's wrong.</p>