cygwin_exception::open_stackdumpfile: Dumping stack trace to array_c__.exe.stackdump

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
#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!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>

int main()
{
    const char sep = '/' ;
    char s1, s2 ;
    int dd, mm, yyyy ;

    std::cout << "enter date as dd/mm/yyyy: " ;

    if( std::cin >> dd >> s1 >> mm >> s2 >> yyyy && s1 == sep && s2 == sep )
    {
        // if( dd/mm/yyyy forms a valid date )
            std::cout << "date is: " << dd << sep << mm << sep << yyyy << '\n' ;

        // else std::cout << "that is not a valid date\n" ;

    }

    else std::cout << "badly formatted input\n" ;
}
Ryochan, if I remove line 5 and add the closing } to the program, it works for me. This probably means that the problem is somewhere else. Can you post a program that compiles and causes the problem?
dhayden wrote:
If I remove line 5 and add the closing } to the program, it works for me.

For me too! "Prova.h" contains functions that I call after the cin.getline, so I don't understand why it must influence the reading...

Can you post a program that compiles and causes the problem?

What do you mean by it?

JLBorges wrote:
I like this way!
Hello ryochan,

Here is another idea using what you have started with with a few changes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <cstdlib>  // <--- Not needed. Will be included through "iostream".
#include <iostream>
#include <string>  // <--- Added.
#include <limits>  // <--- Added.
//#include <stdio.h>      //fgets  <--- Not needed.
//#include "prova.h"

using namespace std;

int main(int argc, char** argv)  // <--- What is the need for argc and argv?
{
	int c;
	std:string data;

	cout << "[...]: ";
	std::cin >> c;
	// <--- To clear the input buffer after the above line.
	std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');  // <--- Requires heder file <limits>.
	
	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()
		std::getline(std::cin, data);        //or fgets (data, 11, stdin);

									  //RUN STOPS HERE!!

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

	return 0;
}


And yes JLBorges has a very good solution.

Hope that helps,

Andy
Emptying the buffer before "switch (c)" ?

I tested the cin.ignore function with "data" as a char[] and it doesn't solve the problem. I'm going to see if does with string data...

In the meantime I corrected the coding error in the functions of the header "prova" and the error does not show up anymore. But my question remains: why calling a function (whether contained in the header or in the main project) after cin.getline should interfere with it?

I include the "prova.h" code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#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 yy[5];
    char mm[3],dd[3];
    for(int i=0;i<=1;i++)  
        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);        
    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(y)) 
        if(d>28) cout<<"Error! "<<yy<<" the year is a leap year!";
    if(m<1 or m>12) std::cout<<"Inexistent month!\n";
    if(d<1 or d>tab[m-1]) std::cout<<"Inexistent day!\n";
}
Last edited on
But my question remains:

In your original post, you're assuming that the program stops before line 26 because you don't see the output from line 26. That output may be buffered, so it's entirely possible that the program is hanging after line 26, not before it. Change line 26 to cout << "hello!" << flush; to see if that's true.
dhyaden wrote:
Change line 26 to cout << "hello!" << flush; to see if that's true.

I cannot see it because now the cygwin exception doesn't show up anymore even if I put the error back where it was in "prova.h" (i.e. I was not considering that function "atoi" requires a null terminated string, so the size of yy,mm and dd has to added by 1).
You shouldn't put functions in header files unless they are inline. Otherwise you'll have multiply defined functions if you #include the file in two different source files.

bis() should return true or false, not 0 or 1.

In rowr, you've allocated enough space for the null-terminated strings, but you haven't actually null-terminated them. So the values of y, m, and d could be anything.

Line 32 could access the array tab out of bounds. You check the bounds at line 31, but line 32 will still execute, even if m<1 or m>12.
Topic archived. No new replies allowed.