Thread: Question on reading matrices from file

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    33

    Question on reading matrices from file

    Ok, I am supposed to read the input from a file that holds info where the matrix dimensions are given, followed by the actual values of each matrix separated by spaces

    Code:
    3 - Rows of first matrix
    4 - Cols of first matrix
    8 2 0 1
    6 7 2 9
    3 6 1 7
    
    4 - Rows of second matrix
    2 - Cols of second matrix
    5 6
    9 2
    1 7
    0 6
    My question is, is there a way to differentiate between what is the dimensions, and what are the values of the matrix.

    Also, I imagine the best way to know I am moving on to the 2nd matrix is once I have looped through the dimensions of the first?

    In the end I am multiplying the two, but I THINK I have that part down, because if I ask the user for each individual input, it works.

    Hope this makes sense, Thanks in advance.

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You know the first two numbers are the dimensions, then you have to read (mxn) numbers for the data, then two numbers for dimensions, then (mxn) numbers for data, ....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  2. Newbish Question file reading question....
    By kas2002 in forum C Programming
    Replies: 23
    Last Post: 05-17-2007, 12:06 PM
  3. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  4. question about reading in strings from a file :>
    By bball887 in forum C Programming
    Replies: 8
    Last Post: 04-13-2004, 06:24 PM