Reading 2 and 3 dimensional arrays from external file. Help please

This is a discussion on Reading 2 and 3 dimensional arrays from external file. Help please within the C Programming forums, part of the General Programming Boards category; Hello, I am trying to write a program that calculates the determinant of a 3*3 matrix using the Laplace expansion ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    13

    Reading 2 and 3 dimensional arrays from external file. Help please

    Hello, I am trying to write a program that calculates the determinant of a 3*3 matrix using the Laplace expansion (if you dont know what this is it doesnt matter, you might still be able to help)

    In an external file, say "elements.dat" i have 9 numbers, which are the elements of the matrix

    eg:

    1 2 3
    4 5 6
    7 8 9

    I need to input these into the program, and evaluate the determinant using the laplace expansion - for this, I need to use an external function to calculate the determinant of the "minor" matricies (i.e the 2*2 matricies found by removing the ith row and jth column), by taking a 2 dimensional array as an input.

    In particular, i need help in this last part, I have no idea how to get the program to make 2-dimensional arrays from the file "elements.dat"

    Thanks! Sorry if this is confusing, im not too confident with programming, but i can try to clarify if needed.

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,049
    One way would to define a 2 dimensional array viz., x2d[3][3].
    Read each row from the file into each array element - x[0][[0:2].
    Repeat above steps so entire array x2d[3][3] has been assigned to.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21