398,818 Members | 3,898 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 398,818 IT Pros & Developers. It's quick & easy.

Reading new lines from text files in c++

Tasha Darke
P: n/a
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

Apr 26 '06 #1
Share this Question
Share on Google+
4 Replies


Victor Bazarov
P: n/a
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
Apr 26 '06 #2

URPradhan
P: n/a
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 ....

Apr 26 '06 #3

Tasha Darke
P: n/a
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

Apr 26 '06 #4

utab
P: n/a
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


Apr 26 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.