473,395 Members | 1,791 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.

"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 4198
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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,...

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.