title: Reading a text file into 2d array
body: <p>I have a text file with just random letters in rows and columns.  All I would like to do is make a 2d array so that it's <code>puzzle[i][j]</code> where if I put <code>printf("%c", puzzle[5][4]);</code> it would simply give me the 4th row and 3rd columns character (since it starts at 0 in an array).  Here is my code so far.</p>
  
  <pre><code>#define MAXROWS     60
  #define MAXCOLS     60
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;math.h&gt;
  
  main()
  {
      FILE *TableFilePtr;
      char TableFileName[100];
      char PuzzleFileName[100];
      char puzzle[MAXROWS][MAXCOLS];
      printf("Please enter the table file name: ");
      scanf("%s",TableFileName);
  
      TableFilePtr=fopen(TableFileName, "r");
  
      if(TableFilePtr == NULL)
      {
          printf("Can't open %s", TableFileName);
          exit(EXIT_FAILURE);
      }
  
      char words;
      int n;
      n=0;
      int i,j,row,col;
      int rowcount, colcount;
      printf("\n how many rows and colums are there?  separate by a space: ");
      scanf("%d %d",&amp;row, &amp;col);
      /*  while(fscanf(TableFilePtr,"%c",&amp;words)!= EOF)
      {
          printf("%c",words);
      }
      */
  
      /*for (colcount=0;colcount&lt;col;colcount++)
      {
          for (rowcount=0;rowcount&lt;row;rowcount++)
          {
              printf("%c ",words);
          }
      printf("\n");
      }
      */
  
  
      for(i=0;i&lt;row;i++){
          for(j=0;j&lt;col;j++){
              fscanf(TableFilePtr, "%c %s\n",&amp;puzzle[i]][j]);
                  //puzzle[i][j]=words;
      //          printf("%c ", puzzle[i][j]);
          }
          printf("\n");
      }
  
  
  }
  </code></pre>
  
  <p>The commented area at the end (just the starting part) works to simply print out the text file in the compiler.  I would like to get it to be in a 2d array though.</p>
  
  <pre><code>for(colcount=0;colcount&lt;col;colcount++){...}
  </code></pre>