Thread: matrix to vector

  1. #1
    Registered User
    Join Date
    Mar 2009

    matrix to vector

    I have a text file with some numbers but in the form of a matrix and I want to store them as a vector. Here is what is in the file:

    3 (since its always square, I only need one number for the rows and columns)
    1 2 3
    0 1 2
    1 4 5

    and my code is:

    {int i;
    float *XAtemp, row_col; 
    FILE *isa;
    for (i=0;i<(row_col*row_col);i++) 
        fscanf(isa," %f ",&XAtemp[i]);
    for (i=0;i<(row_col*row_col);i++)
       printf("\n %f \n", XAtemp[i]);
    return 0;
    is there a way to skip the \n and tell it to continue reading?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Using fscanf, it will automatically discard \n while trying to read a number with %f.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 08:36 PM
  2. Matrix Help
    By HelpmeMark in forum C++ Programming
    Replies: 27
    Last Post: 03-06-2008, 05:57 PM
  3. Gauss-Jordan Matrix Inversion in C++
    By Max_Power82 in forum C++ Programming
    Replies: 3
    Last Post: 12-03-2006, 08:31 PM
  4. Matrix and vector operations on computers
    By DavidP in forum A Brief History of
    Replies: 11
    Last Post: 05-11-2004, 06:36 AM
  5. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 01:26 AM