One row is skipped each time the program scans a matrix from file !
        Posted  
        
            by ZaZu
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by ZaZu
        
        
        
        Published on 2010-05-10T00:20:19Z
        Indexed on 
            2010/05/10
            0:28 UTC
        
        
        Read the original article
        Hit count: 697
        
Hello there,
I had this code working yesterday, but it seems like I edited it a bit and lost the working version. I cant get this to work anymore.
I basically want to scan a matrix from a .txt file. But each time it scans the first row, the second one is skipped, and it reads the third instead :(
Here is my code :
for(i=0;i<=test->rowmat1;i++){
      for(j=0;j<=test->colmat1;j++){
        fscanf(fin,"%f\t",&test->mat[i][j]);                                   
      }
     fscanf(fin,"%*[^\n]",&test->mat[i][j]);
   }
For example, for a matrix of :
1.00    2.00    3.00    
4.00    5.00    6.00    
7.00    8.00    9.00    
10.00   11.00   12.00   
If I extract 3 rows and 3 cols, I get :
1.00    2.00    3.00
7.00    8.00    9.00    
Then fails, it wants to skip over the second line but there is nothing after 10 11 12
Why did it stop working ? What do I have wrong ?
Please help, Thanks in advance.
© Stack Overflow or respective owner