Stack overflow errors

I write code to read information from a file to an array, but I have a problem :Stack overflow errors.

Here is my code:

file "predefine.h"
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
  #ifndef predefine
#define predefine

#include <iostream>
#include <fstream>
#include <string>

#define MAX_IDDOC_LENGTH 256
#define MAX_ISBN_LENGTH 256
#define MAX_TITLE_LENGTH 256
#define MAX_AUTHOR_LENGTH 256
#define MAX_YEAR_LENGTH 256;



#define MAX_DOCUMENT 10000

struct DOCUMENT
{
    char IDDoc[MAX_IDDOC_LENGTH];
    char ISBN[MAX_ISBN_LENGTH];
    char title[MAX_TITLE_LENGTH];
    char author[MAX_AUTHOR_LENGTH];
    char year[MAX_YEAR_LENGTH];
};



#endif 


I want to make an array doc.IDDoc includes all the ID of the file,
an array doc.ISBN includes all the ISBN of the file, etc.....
file .cpp:


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



#include "predefine.h"
using namespace std;

int main()
{

DOCUMENT doc[MAX_DOCUMENT];
char line[256];
int i=0;
ifstream doc_file("Documents.csv",ios::in);
while(doc_file.good())	
{

	doc_file.getline(line,256,',');
	strcpy(doc[i].IDDoc,line);
	doc_file.getline(line,256,',');
	strcpy(doc[i].ISBN,line);
	doc_file.getline(line,256,',');
	strcpy(doc[i].title,line);
	doc_file.getline(line,256,',');
	strcpy(doc[i].author,line);
	doc_file.getline(line,256,'\n');
	strcpy(doc[i].year,line);
	i++;
}
doc_file.close();
}

Ex:
the contents of my Document.csv :


ID |ISBN| title| author| year


1 |2441241| ABC| John| 1995
You are trying to allocate on stack 5 * 256 * 10000 / 1024 / 1024 = 12.2 MB. Stack usually have around 2 MB allocated. Either use more sensible numbers (256 characters for year? Really?), use sensible types (int is good for year), lessen amount of documents.

Or use dynamically allocated memory. To avoid memory managment erors use standard containers: vector instead of array and std::string instead of char[]
I don't know more about vector, can you help me to fix it without editing file "predefine.h" ? because this file was provided by my teacher.
1
2
DOCUMENT doc[MAX_DOCUMENT];
DOCUMENT* doc = new DOCUMENT[MAX_DOCUMENT];
thank you, thanks so much :D :D :D
Topic archived. No new replies allowed.