472,782 Members | 1,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

"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(outputfile.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.getline(buf, 255);

/* split line by spaces and into stimulus vector */
tokens = strtok(buf, " ");
while (tokens != NULL)
{
stimulus.push_back(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 4162
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.getline(buf, 255);
This is the wrong way to read a file
while (inputfile.getline(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
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...
3
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...
3
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...
5
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...
4
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...
4
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
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
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...
1
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...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.