title: How to extract a 2x2 submatrix from a bigger matrix
body: <p>I am a very basic user and do not know much about commands used in C, so please bear with me...I cant use very complicated codes. I have some knowledge in the stdio.h and ctype.h library, but thats about it.
  I have a matrix in a txt file and I want to load the matrix based on my input of number of rows and columns</p>
  
  <p>For example, I have a 5 by 5 matrix in the file. I want to extract a specific 2 by 2 submatrix, how can I do that ?</p>
  
  <p>I created a nested loop using :</p>
  
  <pre><code>FILE *sample
  sample=fopen("randomfile.txt","r"); 
  for(i=0;i&lt;rows;i++){
    for(j=0;j&lt;cols;j++){
       fscanf(sample,"%f",&amp;matrix[i][j]);
     }
   fscanf(sample,"\n",&amp;matrix[i][j]);
  }
  fclose(sample);
  </code></pre>
  
  <p>Sadly the code does not work .. If I have this matrix :</p>
  
  <pre><code>5.00 4.00 5.00 6.00 
  5.00 4.00 3.00 25.00 
  5.00 3.00 4.00 23.00 
  5.00 2.00 352.00 6.00
  </code></pre>
  
  <p>And inputting 3 for row and 3 for column, I get :</p>
  
  <pre><code>5.00 4.00 5.00
  6.00 5.00 4.00
  3.00 25.00 5.00
  </code></pre>
  
  <p>Not only this isnt a 2 by 2 submatrix, but even if I wanted the first 3 rows and first 3 columns, its not printing it correctly....</p>
  
  <p>I need to start at row 3 and col 3, then take the 2 by 2 submatrix !</p>
  
  <p>I should have ended up with : </p>
  
  <pre><code>4.00 23.00 
  352.00 6.00
  </code></pre>
  
  <p>I heard that I can use fgets and sscanf to accomplish this. Here is my trial code :</p>
  
  <pre><code>fgets(garbage,1,fin);
  sscanf(garbage,"\n");
  </code></pre>
  
  <p>But this doesnt work either :(</p>
  
  <p>What am I doing wrong ?</p>
  
  <p>Please help.
  Thanks !</p>