title: Displaying output in C
body: <p>I'm trying to display my output in a 4X4 format. The program receives name of a text file then get the values in the text file and store in the 2D array. Then later displays them like this</p>
  
  <pre class="lang-none prettyprint-override"><code>7 2 4 5 
  5 2 6 4
  2 2 5 5 
  9 2 4 5
  </code></pre>
  
  <p>But the problem is, it doesn't display like that, I'm not sure if it's my loop or what. Any ideas. it runs fine with no errors but the numbers don't display right. Here's my code </p>
  
  <pre><code>int main () {
  
    int i = 0;
    int j = 0;
  
     int value = 0;
     int a[4][4];
     char ch, file_name[100];
     FILE *fp;
  
     printf("Enter file name?");
     gets(file_name);
  
     fp = fopen("file.txt", "r");    
  
     if (fp == NULL)
     {
        perror("Error \n");
     }
     else 
     {
  
         // printf("\n");
          while (!feof(fp) &amp;&amp; fscanf (fp, "%d ", &amp;value))
          {
              a[i][j] = value;
  
           for ( i = 0; i &lt; 4; i++ ) 
                  {
                for ( j = 0; j &lt; 4; j++ ) 
                {
                   printf("%d ",a[i][j] );
                }   
               printf("\n");      
  
             }     
         }
     }
  
      fclose(fp);
  
     return 0;
  
  }
  </code></pre>