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:
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?
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?
#include <iostream>
#include <cstdlib>
#include <stdio.h>
#include <stdlib.h> //atoi
#include <string>
usingnamespace std;
bool bis(int a) //Leap year
{
if(a%400==0 or (a%4==0 and a%100!=0)) return 1;
elsereturn 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";
}
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.
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.