Thread: Help with matrix reading from a file

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2016
    Posts
    1

    Help with matrix reading from a file

    Hello I am having trouble to get desired output for reading a 3x3 matrix from a data file
    The code is::
    insert
    Code:
        FILE *arr;
        float k[3][3]={0.0};
        arr =fopen("data11.txt","r");
        int i,j;
        for(i=0 ;i<3; i++)
            for(j=0; j<3; j++)
            {
                fscanf(arr, "%f%*[^\n]%*c",&k[i][j]);
                printf("%f\n", k[i][j]);
            }
    and data file is::
    0 5 10 54 57 58 90 45
    2 0 15 1 12 12 0 84
    1 3 0 87 48 0 45 9
    4 58 4 0 84 95 78 12

    output should be ::
    0 5 10
    2 0 15
    1 3 0

    instead its showing::
    0 5 10
    54 57 58
    90 45 2

    whats the problem here? I am a novice in programming so if anyone can help I would much appriciate it.Thanks in advance.
    Attached Files Attached Files

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading txt file to a MATRIX
    By Cosmo S in forum C Programming
    Replies: 2
    Last Post: 01-11-2013, 04:40 AM
  2. reading a matrix and printing out the matrix
    By Lina_inverse in forum C Programming
    Replies: 9
    Last Post: 10-23-2012, 04:09 PM
  3. Reading a binary file like a matrix of ints
    By afflictedd2 in forum C++ Programming
    Replies: 3
    Last Post: 01-11-2011, 07:46 AM
  4. Reading a binary file like a matrix of ints
    By afflictedd2 in forum C++ Programming
    Replies: 3
    Last Post: 06-26-2010, 09:45 AM
  5. Reading char matrix from file
    By TriKri in forum C Programming
    Replies: 5
    Last Post: 07-19-2006, 02:05 AM

Tags for this Thread