4 Replies - 460 Views - Last Post: 05 February 2018 - 01:44 AM Rate Topic: -----

#1 ryochan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-February 18

cygwin_exception::open_stackdumpfile: Dumping stack trace to array_c__

Posted 03 February 2018 - 06:11 AM

Hi, i got this error
3 [main] array_c__ 9952 cygwin_exception::open_stackdumpfile: Dumping stack trace to array_c__.exe.stackdump 

when I run the following code:

IDE: Netbeans 8.2 and Cygwin 64 bit.

 
#include <cstdlib>
#include <iostream>
#include <stdio.h>      //fgets
#include "prova.h"

using namespace std;

int main(int argc, char** argv) 
{
    int c;
    char data[11];
    cout<<"[...]";
    cin>>c;
    switch(c) {
        case 1: 
            // [...]
            break;
        case 2:
            cout<<"Insert data (dd/mm/yyyy): ";
            while( getchar() != '\n' );  //to clean the input buffer (read in forum); otherwise it ignores the cin.getline()
            cin.getline(data,10);        //or fgets (data, 11, stdin);
            
            //RUN STOPS HERE!!
            
            cout<<"hello!";
            // [...] 
            break;
    }



P.S.: If I insert 7 or less characters, the error does not show!

Is This A Good Question/Topic? 0
  • +

Replies To: cygwin_exception::open_stackdumpfile: Dumping stack trace to array_c__

#2 jimblumberg  Icon User is offline

  • member icon

Reputation: 5466
  • View blog
  • Posts: 17,018
  • Joined: 25-December 09

Re: cygwin_exception::open_stackdumpfile: Dumping stack trace to array_c__

Posted 03 February 2018 - 07:48 AM

My first suggestion is to stop mixing C-stdio functions and C++ streams. Since you appear to be using C++ I suggest you stick entirely with C++ streams.

Second since this appears to be a C++ program I suggest you use C++ features like std::string instead of the messy and unsafe C-strings.

Third your getline() is not correct. You tell the user to enter the date in "dd/mm/yyyy" format, which requires 11 characters, you seem to be forgetting about the required end of string character that getline() will add to the C-string. Remember unlike C's scanf() function getline() knows that it needs to save space for the end of string character and will automatically reserve room for this character, you should be using 11 (and this should be a named constant instead of the magic number).

This is what I would recommend:

#include <iostream>
#include <string>

using namespace std;

int main()
{
    int c = 0;
    std::string data;
    
    while(c < 1 || c > 2)
    {
        cout << "Please enter a number between (1 and 2): ";
        cin >> c;
        cin.clear();  // Clear any stream errors if present.
        cin.ignore(1024, '\n'); // Empty the input buffer.
    }
    
    switch(c)
    {
        case 1:
            // [...]
            break;
        case 2:
            cout << "Insert data (dd/mm/yyyy): ";
            getline(cin, data);

            //RUN STOPS HERE!!

            cout << "hello! " << data ;
            // [...]
            break;
    }
}




Jim
Was This Post Helpful? 0
  • +
  • -

#3 jimblumberg  Icon User is offline

  • member icon

Reputation: 5466
  • View blog
  • Posts: 17,018
  • Joined: 25-December 09

Re: cygwin_exception::open_stackdumpfile: Dumping stack trace to array_c__

Posted 03 February 2018 - 08:10 AM

Also here with the same answer. Let's not forget about here as well and who knows were else.


Jim

This post has been edited by jimblumberg: 03 February 2018 - 08:21 AM

Was This Post Helpful? 2
  • +
  • -

#4 ryochan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-February 18

Re: cygwin_exception::open_stackdumpfile: Dumping stack trace to array_c__

Posted 05 February 2018 - 01:02 AM

Yes, it is a C++ program. Understood the problem with the getline(), thanks for the suggestions.

Quote

and who knows were else.


.. nowhere else! Well, any help appreciated!
Was This Post Helpful? 0
  • +
  • -

#5 ryochan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 03-February 18

Re: cygwin_exception::open_stackdumpfile: Dumping stack trace to array_c__

Posted 05 February 2018 - 01:44 AM

Yes, it is a C++ program. Understood the problem with the getline(), thanks for the suggestions.

Quote

as well and who knows were else.


Nowhere else! Well, any help appreciated ..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1