title: Reading from a text file and storing in a 2D array
body: <p>I've been trying to store a matrix input in a txt file in a array but it show me this:
  this is the code </p>
  
  <pre><code>   #include &lt;stdio.h&gt;
  
  int main()
  {
      int c, i, j, row, col, nl, cr;
  
      row = col = nl = cr = 0;
  
      FILE *fp = fopen("g.txt", "r");
  
      // Figure out how many rows and columns the text file has
      while ((c = getc(fp)) != EOF)
      {
          if (c == '\n')
              nl++;
          if (c == '\r')
              cr++;
  
          col++;
  
          if (c == '\n')
              row++;
  
         putchar(c);
      }
  
      col = (col - (nl + cr));
      col = (int) (col/row);
  
     // printf("\nnumber of rows is %d\n", row);
  
  
      // read letters into array
  
      char array[row][col];
  
      if ( fp )
         {
          for ( ;; )
                {
              c = getc(fp);
                   if ( c == EOF )
                   {
                          break;
                   }
                   if ( c != '\n' &amp;&amp; c != '\r' )
                   {
                          array[i][j] = c;
  
                      if ( ++j &gt;= col )
                          {
                              j = 0;
                              if ( ++i &gt;= row )
                              {
                                  break;
                              }
                          }
                  }
              }
          fclose(fp);
      }
  
      for ( i = 0; i &lt; row; i++ )
      {
              for ( j = 0; j &lt; col; j++ )
              {
                   putchar( array[i][j]);
              }
              putchar('\n');
      }
      return 0;
  }
  </code></pre>
  
  <p>somone have any idea please?
  exemple of the txt file :</p>
  
  <pre><code>255  50  9  50  1  50  50  1
  50  255  50  50  50  50  50 50
  50  50  255  50  50  50 50  50
  8  50  50  255  50 50  50  50
  50  50  50  50 255 50  50  50
  50  50  50 50  50  255  50  50
  1  50 50  50  50  50  255  50
  2 50  50  50  50  50  50  255 
  </code></pre>
  
  <p>my program show me this:</p>
  
  <pre><code>255 50   9   50  1   50   50   1
  50  255  50  50  50  50   50   50
  50  50   255 50  50  50   50   50
  8   50   50  255 50  50   50   50
  50  50   50  50  255 50   50   50
  50  50   50  50  50  255  50   50
  1   50   50  50  50  50   255  50
  2   50   50  50  50  50   50   255     $■( 1gÍuáþ09■   ı¤ıu"ÒávD   ê$[
  ►  ð²(     ♥       l    ►      ■   
    ê$[ ♥   l       ­²( O»ƒv[ 4■( Qõá
  v♥   #õáv┬²║Oÿ|®v    ñ|®ve┬ív
   ■(     x■( ÿ|®v Ó²⌂    @■(  áƒv╚♀[ L
  ■( w¯ƒv‼   ê■( I┴ávÿ|®v↓┴áv~²║O
     Ó²⌂    \■( ■   ─ ( e┬ívÍ┬29►☺
  </code></pre>
  
  <p>for the input file it show the good one ,but the problem is for the array output i don't undrestand why it show me this caracters</p>