473,769 Members | 1,826 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"Aborted" (while reading file ?)

I am trying to read a file full of numbers followed by spaces (and then
do some cool stuff with it)
My input file looks like this

1 0 1 0 1 0 1
1 1 0 0 1 1 0
(the number of columns is arbitrary, the number of lines is arbitrary.
but all lines have same number of columns)
Now, when I run my program (compiled using g++) I get "Aborted" at the
very end.
I get all my outputs written to my output file perfect. The program is
just crashing after it did its job.

Now, I traced thru the thing I found out it is crashing because it is
going thru one more iteration (when it is not supposed to) .. see "HEY
HEY HEY"

Here's all the relevant code (hopefully)

/* open input vector file */
ifstream inputfile ("input.dat" );

/* create an outputfile */
string outputfile = argv[1];
outputfile = outputfile + ".results";
ofstream outfile(outputf ile.c_str());

/* setting buffer, tokens and stimulus for file parsing */
char buf[255];
char *tokens;
vector <int> stimulus;

/* MAIN EVALUATION LOOP FOR EACH LINE OF INPUTS STARTS HERE */

while (!inputfile.eof ())
{
cout << "HEY HEY HEY\n";
/* clear the stiumuls vector */
stimulus.clear( );

/* read first line of input */
inputfile.getli ne(buf, 255);

/* split line by spaces and into stimulus vector */
tokens = strtok(buf, " ");
while (tokens != NULL)
{
stimulus.push_b ack(atoi(tokens ));
tokens = strtok(NULL, " ");
}

/* initialize NET values to -1*/
initializenet(-1);

/* set all inputs from stimulus */
for (int i = 0; i < inputnets.size( ); i++)
{
NET[inputnets.at(i)] = stimulus.at(i);
}

/* go through the evaluate loop */
evaluateloop();

/* write evaluated outputs to file */
for (int i = 0; i < outputnets.size (); i++)
{
outfile << NET[outputnets.at(i )] << " ";
}
outfile << endl;
}
return 0;
}

Like I said earlier, the code goes thru all my lines of input vectors,
evaluates and writes out correct output to my "outfile". But it
shamelessly crashes because it is going thru one more time in the loop
(I know this because it said "Aborted" after printing "HEY HEY HEY",
and my output file looks correct)

By the way, my input file will not have an extra line after the last
line, so for example

--------------file starts here--------------
1 0 1 0 1
1 1 0 0 1
--------------file ends here----------------

I am also probably screwing up some pointer stuff (haha, that's
expected)

So what's causing my program to die ?

Sep 17 '05 #1
2 4228
ma******@gmail. com wrote:
I am trying to read a file full of numbers followed by spaces (and then
do some cool stuff with it)
My input file looks like this

1 0 1 0 1 0 1
1 1 0 0 1 1 0
(the number of columns is arbitrary, the number of lines is arbitrary.
but all lines have same number of columns)
Now, when I run my program (compiled using g++) I get "Aborted" at the
very end.
I get all my outputs written to my output file perfect. The program is
just crashing after it did its job.

Now, I traced thru the thing I found out it is crashing because it is
going thru one more iteration (when it is not supposed to) .. see "HEY
HEY HEY"

It must be commonest newbie mistake.
while (!inputfile.eof ())
{
cout << "HEY HEY HEY\n";
/* clear the stiumuls vector */
stimulus.clear( );

/* read first line of input */
inputfile.getli ne(buf, 255);
This is the wrong way to read a file
while (inputfile.getl ine(buf, 255))
{
cout << "HEY HEY HEY\n";
/* clear the stiumuls vector */
stimulus.clear( );


This is the right way.

eof() tells you why the last read failed. It does not tell you that the
next read is going to fail. That is why you are going round the loop one
too many times.

john
Sep 17 '05 #2
that did it.
thanks. :-)

Sep 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6510
by: Elliot M. Rodriguez | last post by:
A few of our customers cannot access one of the pages on our vb.net asp.net site. The problems are limited to only a few people, but these people have the problem regularly. The page in question is a simple details page from a link selected from another page. The details page calls a procedure that calls our database, returns a recordset, and does some simple binding to some web controls. This page works for most of our customers. For...
3
1819
by: SKG | last post by:
I have a web page with customized datagrid and a usercontrol. Sometimes iam getting "operation aborted" internet explorer cannot find site <web page name..> when i click back button i see the page is loaded. I found my viewstate has lot of junk 3 to 4 pages. I increased temporary cache,deleted temporary files,cookies,third party installs of the ie but still problem persists. Thanks!!!
3
2946
by: Stephen Miller | last post by:
I have an ASP.Net application that sends a NetworkStream to a .Net Service, which has a TcpListener listening on a port for the ASP.Net client. When it receives a request it creates a new thread with the AddressOf a class that runs a long data intensive process that can take between 1-15 minutes and results in the creation of a uniquely named file. Meanwhile, I want my ASP.Net application to sit and wait until the file appears at a...
5
2030
by: Alan Silver | last post by:
Hello, I have a page that is supposed to do some checking, and if OK, set a session variable before redirecting to another page. The following code is a simplified version, I have hard-coded the basket ID and removed a load of extra checking... public partial class GoToCheckout : Page { public void Page_Load(Object o, EventArgs e) { try {
4
6073
by: hitendra15 | last post by:
Hi following is the code which sends file to the browser means user can download file, but the code generates error message Thread Being Aborted., will any one put their thoughts protected void SendFileToBrowser(string strpath) { try { FileInfo objFileInfo = new FileInfo(strpath);
4
4920
by: Totto | last post by:
Hi, I'm doing a server.transfer from a click event of a button, but an exception is raised with "Thread was being aborted" Anyone know why? Thanks Tor
1
3228
by: active | last post by:
When I run an app outside of the IDE I get the exception Thread was being aborted Does that error mean something to you? Any idea what might be causing it? ++++++++++++++++
1
2458
by: -Lost | last post by:
This is more of a post to inform, unless of course I am missing something fundamental, in which case I would appreciate anyone explaining it. Based on Mr. Michaux's camelizeStyle function I wrote: function create_style(style) { var p = document.createElement('p'); var t = document.createTextNode('Just something to fill the P.');
1
2016
by: rmgalante | last post by:
I was wondering if anyone knows whether MS has a fix for the Menu Control. If the page is loading while you mouse over a menu control with child menus that pop out, you can generate the following error in IE. Internet Explorer cannot open the Internet site... http://www.... Operation aborted
0
9579
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
9415
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10032
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...
0
8860
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
7392
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
6661
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5293
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...
1
3947
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2810
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.