473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Reading new lines from text files in c++

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
4 3489
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: jamait | last post by:
Hi all, I m trying to read in a text file into a datatable... Not sure on how to split up the information though, regex or substrings...? sample: Col1 Col2 ...
18
by: Michael | last post by:
Hi, I moved to c++ from c, and wanted to know what the best way to read data from files is in c++. Any thoughts? fscanf() is possible but fairly painful! Regards Michael
50
by: Michael Mair | last post by:
Cheerio, I would appreciate opinions on the following: Given the task to read a _complete_ text file into a string: What is the "best" way to do it? Handling the buffer is not the problem...
40
by: googler | last post by:
I'm trying to read from an input text file and print it out. I can do this by reading each character, but I want to implement it in a more efficient way. So I thought my program should read one...
6
by: Adrian Lin | last post by:
Is there a way to read a specfic line in a text file? For instance if I wanted to just read the 5th line is that possible without having to step through the other lines? Essentially I am doing huge...
11
by: Michael McGarry | last post by:
Hi, I am reading strings from a text file using fscanf("%s", currToken); This returns strings delimited by whitespace. How can I tell if the string was followed by a carriage return in the...
3
by: bbepristis | last post by:
Hey all I have this code that reads from one text file writes to another unless im on a certian line then it writes the new data however it only seems to do about 40 lines then quits and I cant...
1
by: akalmand | last post by:
Hi there, I am writing a code to read some data from the text files. The number of text files is not fixed and could be more that 15. the length of each file is large... close to 100,000 on an...
3
by: astroumut | last post by:
Hi, I need a help regarding reading a line in a text file. I have some files with columns but some header information at the top. Some of these header lines begin with a *, and some of them with...
2
by: rka77 | last post by:
Hi, I am trying to make a Python2.6 script on a Win32 that will read all the text files stored in a directory and print only the lines containing actual data. A sample file - Set : 1 Date:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.