473,813 Members | 2,969 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3519
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
2817
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 Col3 Col4 A0012430 REKAL TVÄTTMEDEL EKOMAX 0,5L ST 75.9000
18
2250
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
5048
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 -- the character input is a different matter, at least if I want to remain within the bounds of the standard library.
40
4624
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 line at a time and print it out. How can I do this? I wrote the code below but it's not correct since the fscanf reads one word (terminating in whitespace or newline) at a time, instead of reading the whole line. #include <stdio.h> void...
6
1870
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 calculations in which genetic matrices are saved in text files instead of being held in arrays that take up memory. I am trying to do something where the genetic matrix is stored in a text file and I call specfic lines for calculations then put...
11
3021
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 file? Michael
3
2181
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 figure out why any help would be much apprechiated 1. Dim line_num As Integer 2. Dim filename2 As String 3.
1
1587
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 average. some of them are extra large. The data that I have to read will always be at the bottom and will be in the last 5 -20 line in the files depending upon their size. small files will have 5 line and large files will have 20 lines to read. Can...
3
16537
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 nothing. I have to read the 9th line and 5th column, then extract the number from here and save it to another text file. I was thinking of some solutions. 1) I can delete the first 8 lines and read the columns straightforward. 2) I first read...
2
4103
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: 10212009 12 34 56 25 67 90 End Set ******** Set: 2 Date: 10222009
0
9734
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10664
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10404
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10417
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10139
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9220
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7678
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5568
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3881
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.