Reading new lines from text files in c++

Discussion in 'C++' started by Tasha Darke, Apr 26, 2006.

  1. Tasha Darke

    Tasha Darke Guest

    Hi,

    I'm having a problem finding the answer to a problem I'm having. I'm
    trying to read data for a neural network from a text file where the
    inputs are on one line, and the expected output the next. I can read
    the inputs no problem, but where I expect the program to move to the
    next line it instead continues to read "white space" on the same line.

    The text file looks something like this
    -1 -1 0 .......... -7 0
    0.80000

    I see -7 and 0 going into the training data array, followed by a load
    of 0s, and not 0.8. I'm using fscanf to grab the numbers out (I'll
    admit to not being very proficient with C++, and yes this is for Uni
    coursework), since all the documentation I've read indicates that
    fscanf will jump whitespace (and I therefore assumed lines).

    I'm evidently missing something major here, so any assistance/links
    would be gratefully recieved.

    If you need to see the code in progress, I will happily post.

    Tasha
    Tasha Darke, Apr 26, 2006
    #1
    1. Advertising

  2. Tasha Darke

    URPradhan Guest

    Hi

    Are you amy be reading file with the help of while loop with a
    condition of EOF or new line charater (may be) .. see (check) if ur
    doing it by new line character ....
    URPradhan, Apr 26, 2006
    #2
    1. Advertising

  3. Tasha Darke wrote:
    > I'm having a problem finding the answer to a problem I'm having. I'm
    > trying to read data for a neural network from a text file where the
    > inputs are on one line, and the expected output the next. I can read
    > the inputs no problem, but where I expect the program to move to the
    > next line it instead continues to read "white space" on the same line.
    >
    > The text file looks something like this
    > -1 -1 0 .......... -7 0
    > 0.80000
    >
    > I see -7 and 0 going into the training data array, followed by a load
    > of 0s, and not 0.8. I'm using fscanf to grab the numbers out (I'll
    > admit to not being very proficient with C++, and yes this is for Uni
    > coursework), since all the documentation I've read indicates that
    > fscanf will jump whitespace (and I therefore assumed lines).
    >
    > I'm evidently missing something major here, so any assistance/links
    > would be gratefully recieved.
    >
    > If you need to see the code in progress, I will happily post.


    Don't offer. Read the FAQ 5.8 and follow its recommendations.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Apr 26, 2006
    #3
  4. Tasha Darke

    Tasha Darke Guest

    Whoops, sorry for not reading the FAQ properly. I'll be sure to follow
    it next time I post.
    Thanks for the pointers, I've managed to sort the problem out - I
    wasn't opening the file correctly (binary instead of text mode).

    Thanks again

    Tasha
    Tasha Darke, Apr 26, 2006
    #4
  5. Tasha Darke

    utab Guest

    Take a look at the standard getline() function and string streams in
    C++ book, I guess you will find the answer, If I got that right

    getline reads whole line excluding the newline character
    and in brief you can extract the necessary information with string
    streams I guess

    Regards,

    Tasha Darke wrote:
    > Hi,
    >
    > I'm having a problem finding the answer to a problem I'm having. I'm
    > trying to read data for a neural network from a text file where the
    > inputs are on one line, and the expected output the next. I can read
    > the inputs no problem, but where I expect the program to move to the
    > next line it instead continues to read "white space" on the same line.
    >
    > The text file looks something like this
    > -1 -1 0 .......... -7 0
    > 0.80000
    >
    > I see -7 and 0 going into the training data array, followed by a load
    > of 0s, and not 0.8. I'm using fscanf to grab the numbers out (I'll
    > admit to not being very proficient with C++, and yes this is for Uni
    > coursework), since all the documentation I've read indicates that
    > fscanf will jump whitespace (and I therefore assumed lines).
    >
    > I'm evidently missing something major here, so any assistance/links
    > would be gratefully recieved.
    >
    > If you need to see the code in progress, I will happily post.
    >
    > Tasha
    utab, Apr 26, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    1,175
  2. Joe Wright
    Replies:
    0
    Views:
    507
    Joe Wright
    Jul 27, 2003
  3. Murali
    Replies:
    2
    Views:
    558
    Jerry Coffin
    Mar 9, 2006
  4. Ouray Viney
    Replies:
    3
    Views:
    421
  5. Cah Sableng
    Replies:
    0
    Views:
    236
    Cah Sableng
    Apr 23, 2007
Loading...

Share This Page