473,395 Members | 1,516 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,395 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 3490
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:...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.