Can I fscanf from temporary file?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • itmfl
    New Member
    • Oct 2008
    • 3

    Can I fscanf from temporary file?

    I am working in C. I'm trying to copy values from one file to another new file minus the first line. Then I am setting the values in the new file to a matrix.
    The first file contains:

    Matrix1
    2 3
    1 6
    2 4
    3 5

    I need to find some way to set the integers to int matrix1[4][2].
    Is there a better way to do this? This is what I have so far:

    Code:
    tempFile=fopen("/Users/ITMFL/Desktop/tempFile1.txt","r+");
    input1=fopen(inputFile,"r+");
    
    
    
    b=1;
    
    for (i=0;i<=10;i++)
    	{
    	fgets(cc[i],100,input1);
    	}
    for (i=b;i<=5;i++)
    	{
    	fputs(cc[i],tempFile);	
    	}
    fclose(tempFile);
    
    for (i=0;i<=20;i++)
    	{
    		for (j=0;j<=20;j++)
    			{
    			fscanf(tempFile,"%d",&matrix1[i][j]);
    			printf(" %d ",matrix1[i][j]);
    			}
    	}
    fclose(tempFile);
    fclose(input1);
    When I use this code, all that matrix1[i][j] returns are 0's.
  • curiously enough
    New Member
    • Aug 2008
    • 79

    #2
    What the **** are you using fputs and fgets for?
    And why did you close tempfile twice?
    Last edited by Banfa; Oct 21 '08, 10:19 PM. Reason: removed swear words

    Comment

    Working...