shorting file with column data

I have two files. In file 1 there are three columns with 910000 data. In file 2 there are 4 columns with 232245 data. File 1 (col1) and file 2 (col2) has the same parameter and file 1 (col2) and file2 (col3) has the same parameter.
Now I want short the file 1 with file2 (col2 and col 3) and get the out put. i am trying with this code but it is giving error.

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
  void main()
{

	ifstream final2("file1.txt");
	ifstream final3("file2.txt");
	ofstream land("landuse.txt");

	int ID[232245], east[232245], nort[232245], n_soils[232245];
	int col1, col2, col3;

	for(int i = 0; i<=232244; i++)
	{
		final3>>ID[i]>>east[i]>>nort[i]>>n_soils[i];

		while(final2>>col1>>col2>>col3)
		{
			if(east[i] == col1 && nort[i] == col2)
			{
				land<<col1<<'\t'<<col2<<'\t'<<col3<<endl;
			}
		}
	}


	system("pause");
Hi there,

If you are getting errors, please make sure to copypaste them in your post.
That way we can analyze the problem more quickly and help you better.

All the best,
NwN
the error msg: Unhandled exception at 0x00fa7867 in final-landuse.exe: 0xC00000FD: Stack overflow.

it is not completing the run.
I have reduced the array size to 100000 and then the file is working fine.
Hi there,

Stack overflow means that the space which your operating system has assigned to your program as "stack space" has ran out. You could try and declare the array on the heap in stead:

int ID = int[232245];

This post has some good info on this subject: http://www.cplusplus.com/forum/general/12086/

All the best,
NwN
"short a file"?

Two tables. Join by id field(s). Basic SQL query operation.

GNU has "join" command.

The question is, what is the priority? Getting the job done or use of C++. If the latter, put the smaller set into std::map and then filter the larger set. Concatenate the keyfields to one too.
Topic archived. No new replies allowed.