[RESOLVED] cygwin_exception::open_stackdumpfile: Dumping stack trace to array_c__.exe.stackdump
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: [RESOLVED] cygwin_exception::open_stackdumpfile: Dumping stack trace to array_c__.exe.stackdump

  1. #1
    Join Date
    Feb 2018
    Posts
    6

    [RESOLVED] cygwin_exception::open_stackdumpfile: Dumping stack trace to array_c__.exe.stackdump

    Hi, i got this error
    Code:
    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.

    Code:
     
    #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!

  2. #2
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,143

    Re: cygwin_exception::open_stackdumpfile: Dumping stack trace to array_c__.exe.stackd

    The issue is with the while loop. In this context you don't need it. Consider

    Code:
    	const int data_size = 11;
    	char data[data_size];
    
    	cout << "Insert data (dd/mm/yyyy): ";
    	cin.getline(data, data_size);
    	cout << data << endl;
    When you need to clean the input buffer depends upon how data is read. If you use stream extraction (>>) then this ignores white_space before data and stops extracting when a white_space is found (leaving the terminating white_space). getline() reads data from the current stream position until a white_space char is found which is extracted - it doesn't ignore leading white_space which extraction does. Hence if you mix stream extraction with getline() you need to deal with these differences. If the terminating white_space is not to be extracted, then .get() can be used instead of getline(). Also if an extraction causes a stream failure (eg trying to extract a number from a non-numerical input) then after the stream state has been re-set to good the 'bad' chars need to be extracted otherwise the extraction will fail again.

    Note that the size specified for getline() includes the terminating null.

    Why not use the c++ std::string rather than a c-style null-terminated string?

    Code:
    	string data;
    
    	cout << "Insert data (dd/mm/yyyy): ";
    	getline(cin, data);
    	cout << data << endl;
    Last edited by 2kaud; February 3rd, 2018 at 08:36 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.6.6)

  3. #3
    Join Date
    Feb 2018
    Posts
    6

    Re: cygwin_exception::open_stackdumpfile: Dumping stack trace to array_c__.exe.stackd

    If I remove the while loop the program shows the exception.

    If I combine the while loop with the (suggested elsewhere):

    Code:
     cin.ignore(1024, '\n');       // Empty the input buffer.
    the program runs but "data" is not read correctly.

    By the way, why I have to use size as a constant?

    P.S.: yes, I begin to realize that with strings things gets easier..

  4. #4
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,143

    Re: cygwin_exception::open_stackdumpfile: Dumping stack trace to array_c__.exe.stackd

    What does the rest of the program do? Would you post your full code as the issue may lie elsewhere.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.6.6)

  5. #5
    Join Date
    Feb 2018
    Posts
    6

    Re: cygwin_exception::open_stackdumpfile: Dumping stack trace to array_c__.exe.stackd

    It is possible, because if I remove #include "prova.h" the error does not show!

    Main.cpp

    Code:
    #include <cstdlib>
    #include <iostream>
    #include <stdio.h>      //fgets
    #include <string>
    
    #include "prova.h"      //HEADER with functions
    
    using namespace std;
    
    int main(int argc, char** argv) 
    {
        int c,aa;
        const int size = 11;
        char data[size];
        cout<<"Selections [...]\n";
        cin>>c;
        switch(c) {
            case 1: 	//Leap year
                cout<<"Insert year: ";
                cin>>aa;
                if(bis(aa)==1) cout<<aa<<" is a leap year";
                else cout<<aa<<" is not a leap year";
                break;
            case 2: 	//Confronting dates
                cout<<"Insert the first date (dd/mm/yyyy): ";
                
                while( getchar() != '\n' );    
                cin.clear();  
                cin.ignore(1024, '\n'); 
                cin.getline(data,size);
                
                if(rorw(data)==1)
                {
                    cout<<"Insert the second date (dd/mm/yyyy): ";
                    char data2[size];
                    
                    /*if(rorw(data)==2) CODE YET TO BE WRITTEN*/
                   
                    break;
                }
                else break;
        }
       
    }
    prova.h

    Code:
    #include <iostream>
    #include <cstdlib>
    #include <stdio.h>
    #include <stdlib.h>     //atoi
    #include <string>
    
    using namespace std;
    
    bool bis(int a)   //Leap year
    {
        if(a%400==0 or (a%4==0 and a%100!=0)) return 1;
        else return 0;
    }
    
    bool rorw(char data[])  //check if the date is correct
    {
        char aa[4];
        char mm[2],dd[2];
        for(int i=0;i<=1;i++)   //estrae il vettore char[] 'gg';
            dd[i]=data[i];
        for(int i=0;i<=1;i++)
            mm[i]=data[i+3];
        for(int i=0;i<=3;i++)
            yy[i]=data[i+6];
        int y=atoi(yy);            //converte in int;   
        int m=atoi(mm);
        int d=atoi(dd);
        int tab[12]={31,28,31,30,31,30,31,31,30,31,30,31};
        if(bis(a)) 
            if(d>28) cout<<"Error! "<<aa<<" the year is a leap year!";
        if(m<0 or m>12) std::cout<<"Inexistent month!\n";
        if(d<0 or d>tab[m-1]) std::cout<<"Inexistent day!\n";
    }

  6. #6
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,143

    Re: cygwin_exception::open_stackdumpfile: Dumping stack trace to array_c__.exe.stackd

    Does this code compile?

    Code:
     yy[i]=data[i+6];
    yy isn't defined!

    Code:
     if(bis(a))
    a isn't defined!

    atoi() requires a null terminated string so

    Code:
    char yy[5] = {0}, mm[3] = {0}, dd[3] = {0};
    Code:
    if(m<0 or m>12)
    Months and days start at 1, not 0!

    PS rorw() is suppposed to return a value of type bool but the function doesn't return any values!

    Also

    Code:
    bool bis(int a)   //Leap year
    {
        if(a%400==0 or (a%4==0 and a%100!=0)) return 1;
        else return 0;
    }
    can be simplified to

    Code:
    bool bis(int a)   //Leap year
    {
        return a%400 == 0 or (a%4 == 0 and a%100 != 0);
    }
    Also note that whilst or and and are part of standard c++, these are not in common usage. Usually || is used for logical or and && for logical and.

    Code:
    cin >> c;
    ...
     cin.getline(data,size);
    As explained in post #2, these two types of obtaining data are not compatible when used together. If you really want to mix them then after the stream extraction (>>) you need to remove the trailing \n from the input stream. Consider

    Code:
    	int c = 0;
    
    	cout << "Selections [...]\n";
    	if (cin >> c)
    		cin.ignore(1000, '\n');
    If a non-number is entered, c is still 0 and (cin...) returns false so the .ignore() isn't executed. If a number is entered, then c has the number, (cin...) returns true and the characters following the entered number are removed ready for either a next stream extraction or getline().


    By the way, why I have to use size as a constant?
    It is good practice to define as a const variable any data number used in the program so that if any change is required it is only changed in one place. Also giving a name to a number indicates its purpose.
    Last edited by 2kaud; February 5th, 2018 at 04:29 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.6.6)

  7. #7
    Join Date
    Feb 2018
    Posts
    6

    Re: cygwin_exception::open_stackdumpfile: Dumping stack trace to array_c__.exe.stackd

    Sorry I'm translating from Italian: "a" is "y" and "aa" is "yy".

    Months and days start at 1, not 0!
    Shame on me!
    Actually I was still developing the function "rorw" ...

    Anyway, your solution (and the while loop either):
    Code:
     int c = 0;
    
    	cout << "Selections [...]\n";
    	if (cin >> c)
    		cin.ignore(1000, '\n');
    works only if I remove #include "prova.h" (and releated references).

    I don't understand why calling a function (whether contained in the header or in the main project) after cin.getline should interfere with it?!

  8. #8
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,143

    Re: cygwin_exception::open_stackdumpfile: Dumping stack trace to array_c__.exe.stackd

    I don't understand why calling a function (whether in the header or in the main project) after cin.getline should interfere with it?
    The problem in rorw() is atoi(). As explained in post #6, the c-style string passed needs to be null terminated - which in the code in post #5 isn't. Also in prova.h both cstdlib and stdlib.h are included. Consider

    Code:
    #include <iostream>
    #include <cstdlib>
    #include <cstdio>
    #include <string>
    cstdlib is the c++ version of stdlib.h - same for cstdio and stdio.h. You don't include both ctsdlib and stdlib.h
    Last edited by 2kaud; February 5th, 2018 at 06:10 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.6.6)

  9. #9
    Join Date
    Feb 2018
    Posts
    6

    Re: cygwin_exception::open_stackdumpfile: Dumping stack trace to array_c__.exe.stackd

    You are right, the problem in rorw() is atoi(). Considering the terminating "null" solved the problem!

    In some way the coding error in the function manages to "retrocause" the cygwin exception before the function is actually called!!!

  10. #10
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,143

    Re: cygwin_exception::open_stackdumpfile: Dumping stack trace to array_c__.exe.stackd

    In some way the coding error in the function manages to "retrocause" the cygwin exception before the function is actually called!!!
    No. The run-time problem occurs in rorw() when rorw() is called immediately following data input in case 2.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.6.6)

  11. #11
    Join Date
    Feb 2018
    Posts
    6

    Re: cygwin_exception::open_stackdumpfile: Dumping stack trace to array_c__.exe.stackd

    Thank you very much for the help!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)