Getting a SIGTERM signal error while reading a file

  • (2 Pages)
  • +
  • 1
  • 2

28 Replies - 1055 Views - Last Post: 14 September 2012 - 06:57 PM Rate Topic: ***** 1 Votes

#1 jtreiner  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 53
  • Joined: 20-February 12

Getting a SIGTERM signal error while reading a file

Posted 12 September 2012 - 07:40 PM

I am for some reason getting a SIGTERM signal sent from the os when running my program.

        top_io.open("type_of_pixel.txt", ios::out | ios::in);
        if (top_io.is_open() && !top_io.fail() && top_io.good()) {
            top_io.seekg(0, ios::beg);
            top_io.seekp(0, ios::beg);
            int test = 0;
            for (long a = 0; !top_io.eof(); a++) {
                top_io << test;
                if (a == Platform_del) {
                    top_io << 0;
                }
            }
            
            top_io.close();
            mouse_was_clicked = false;
        
    }
        else {
            cout << "Error";
        }



it appears the signal is coming from this line:
 top_io << test; 


I am using xcode on a mac with c++. PLease help me.
Thanks :bigsmile:

This post has been edited by jtreiner: 12 September 2012 - 07:42 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Getting a SIGTERM signal error while reading a file

#2 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1394
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Getting a SIGTERM signal error while reading a file

Posted 12 September 2012 - 07:48 PM

for (long a = 0; !top_io.eof(); a++)
This loop terminates when an I/O operation causes the eofbit to be set.

What line within that loop would cause the eofbit to be set?
Was This Post Helpful? 1
  • +
  • -

#3 jtreiner  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 53
  • Joined: 20-February 12

Re: Getting a SIGTERM signal error while reading a file

Posted 12 September 2012 - 07:49 PM

The file was written in another block of code. I think that should answer your question. If not please explain.
Was This Post Helpful? 0
  • +
  • -

#4 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1394
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Getting a SIGTERM signal error while reading a file

Posted 12 September 2012 - 07:52 PM

> The file was written in another block of code. I think that should answer your question.

Ok, I don't think you understood what I'm asking at all.

Why did you type !top_io.eof() in that code?
Was This Post Helpful? 1
  • +
  • -

#5 jtreiner  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 53
  • Joined: 20-February 12

Re: Getting a SIGTERM signal error while reading a file

Posted 12 September 2012 - 07:54 PM

I tried something else which fixed the SIGTERM signal but caused another problem:

        top_io.open("type_of_pixel.txt", ios::out | ios::in);
        if (top_io.is_open() && !top_io.fail() && top_io.good()) {
            top_io.seekg(0, ios::beg);
            top_io.seekp(0, ios::beg);
            int test = 0;
            for (long a = 0; !top_io.eof(); a++) {
                top_io << test;
                if (a == Platform_del) {
                    top_io << 0;
                    return;
                }
            }
            
            top_io.close();
            mouse_was_clicked = false;
        
    }
        else {
            cout << "Error";
        }


I added the return line but now my program says error in the console.

View PostOler1s, on 12 September 2012 - 07:52 PM, said:

> The file was written in another block of code. I think that should answer your question.

Ok, I don't think you understood what I'm asking at all.

Why did you type !top_io.eof() in that code?

It is so the loop will end once it reaches the end of the file.
Was This Post Helpful? 0
  • +
  • -

#6 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1394
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Getting a SIGTERM signal error while reading a file

Posted 12 September 2012 - 08:00 PM

Quote

It is so the loop will end once it reaches the end of the file.
Yes, very good. Now, tell me, how do you reach the end of the file? Which line of code could cause you to hit the end of the file?
Was This Post Helpful? 1
  • +
  • -

#7 jtreiner  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 53
  • Joined: 20-February 12

Re: Getting a SIGTERM signal error while reading a file

Posted 12 September 2012 - 08:02 PM

shouldn't ">>" put the next line of code into a variable and it keeps going forward until it reaches the end? :?: :?: :?: :?:
Was This Post Helpful? 0
  • +
  • -

#8 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1394
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Getting a SIGTERM signal error while reading a file

Posted 12 September 2012 - 08:08 PM

> shouldn't ">>" put the next line of code into a variable

Correct. Here's what I want you to do:

Copy paste only the line of code that has >> in it. Highlight the >> in red for us to see.
Was This Post Helpful? 1
  • +
  • -

#9 jtreiner  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 53
  • Joined: 20-February 12

Re: Getting a SIGTERM signal error while reading a file

Posted 12 September 2012 - 08:12 PM

Oh hahahahaha :stupid:

EVERYONE THUMBS UP older1s

BUt i am still having the same problem

This post has been edited by jtreiner: 12 September 2012 - 08:13 PM

Was This Post Helpful? 0
  • +
  • -

#10 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1394
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Getting a SIGTERM signal error while reading a file

Posted 12 September 2012 - 08:18 PM

Post your fixed code that should have resolved the SIGTERM issue.

This post has been edited by Oler1s: 12 September 2012 - 08:19 PM

Was This Post Helpful? 1
  • +
  • -

#11 jtreiner  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 53
  • Joined: 20-February 12

Re: Getting a SIGTERM signal error while reading a file

Posted 13 September 2012 - 01:36 PM

        top_io.open("type_of_pixel.txt", ios::out | ios::in);
        if (top_io.is_open() && !top_io.fail() && top_io.good()) {
            top_io.seekg(0, ios::beg);
            top_io.seekp(0, ios::beg);
            int test = 0;
            for (long a = 0; !top_io.eof(); a++) {
                top_io >> test;
                if (a == Platform_del) {
                    top_io << 0;
                    return;
                }
            }
            
            top_io.close();
            mouse_was_clicked = false;
        
    }
        else {
            cout << "Error";
        }



I added the
 return; 
line and it fixed the SIGTERM problem but now I get "error" in the console.
The error is from:
        else {
            cout << "Error";
        }


Was This Post Helpful? 0
  • +
  • -

#12 jtreiner  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 53
  • Joined: 20-February 12

Re: Getting a SIGTERM signal error while reading a file

Posted 13 September 2012 - 02:27 PM

Can someone please help me :helpsmilie:
Was This Post Helpful? -1
  • +
  • -

#13 jimblumberg  Icon User is offline

  • member icon

Reputation: 3054
  • View blog
  • Posts: 9,291
  • Joined: 25-December 09

Re: Getting a SIGTERM signal error while reading a file

Posted 13 September 2012 - 02:34 PM

You need to show a little patience.

First why do you have so many conditions in your if statement?
   if (top_io.is_open() && !top_io.fail() && top_io.good()) {

A simple way of checking if a file opened correctly is:
   if (top_io) {

This checks if there are any error conditions.

Next, what type of stream is top_io? An ifstream, ofstream, fstream?


Jim
Was This Post Helpful? 1
  • +
  • -

#14 jtreiner  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 53
  • Joined: 20-February 12

Re: Getting a SIGTERM signal error while reading a file

Posted 13 September 2012 - 03:22 PM

fstream
Was This Post Helpful? 0
  • +
  • -

#15 jtreiner  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 53
  • Joined: 20-February 12

Re: Getting a SIGTERM signal error while reading a file

Posted 13 September 2012 - 04:06 PM

I don't mean to be impatient but I need to get this code fixed as soon as possible. If anyone can help me please do.
Thanks
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2