www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/07/03/11:45:16

From: jason_hsu AT my-deja DOT com
Newsgroups: comp.os.msdos.djgpp
Subject: BLOCKADE: multidimensional string array
Date: Mon, 03 Jul 2000 15:24:17 GMT
Organization: Deja.com - Before you buy.
Lines: 99
Message-ID: <8jqb6e$li5$1@nnrp1.deja.com>
NNTP-Posting-Host: 24.18.171.165
X-Article-Creation-Date: Mon Jul 03 15:24:17 2000 GMT
X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)
X-Http-Proxy: 1.1 x61.deja.com:80 (Squid/1.1.22) for client 24.18.171.165
X-MyDeja-Info: XMYDJUIDjason_hsu
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

As I mentioned before, I am working on a function that gathers data
(strings) from tab-delimited text files (spreadsheets stored in text
format) of varying sizes.

I am trying to store the data in a large multidimensional array, but no
matter what I do, I keep getting the dreaded SIGSEGV error when I run
the program.  I tried allocating a 1000x1000 array, but the SIGSEGV
error still shows up.  I used dynamic memory allocation with the heap
(string* array;array=new string), but the error won't go away.

Can anyone tell me what it will take to resolve this issue regarding a
large multidimensional array?  Is there a viable alternative to a large
2D string array?  Is there a way to make this large 2D string array
work?

The code is:

/*	Get data from file.  By the way, the program includes the
#include <string> declaration.	*/
void get_data(string file_name)
{
	char ch;
	int row_num=1, row_num_max=1, col_num=1, col_num_max=1;
	fstream fin;
	fin.open(file_name.c_str(), ios::in);
	if (!fin)
		{
		cout << "Unable to open file";
		}
	while (!fin.eof())
		{
		fin.get(ch);
		if (ch=='\t')
			{
			col_num++;
			if (col_num>col_num_max)
				{
				col_num_max=col_num;
				}
			}
		else if (ch=='\n')
			{
			row_num++;
			col_num=1;
			}
		}

	row_num_max=row_num-1;

	row_num=1;
	col_num=1;

	string* rc_data;
	rc_data=new string;

	fin.clear ();
	fin.seekg (0, ios::beg);

	while (!fin.eof())
		{
		fin.get(ch);
		if (ch=='\t')
			{
			col_num++;
			}
		else if (ch=='\n')
			{
			row_num++;
			col_num=1;
			}
		else
			{
			rc_data[row_num][col_num]=rc_data[row_num]
[col_num]+ch;
			}
		}
	fin.close();
	cout<<rc_data[13][4];
	/*
	for (row_num=1;row_num<=row_num_max;row_num++)
		{
		for (col_num=1;col_num<=col_num_max;col_num++)
			{
			cout<<"\n"<<rc_data[row_num][col_num]<<"\n";
			}
		}
	*/
	cout<<"\nEND\n";

}

--
Jason Hsu, KB9PNZ
jason_hsu AT apexmail DOT com
http://www.bigfoot.com/~jason_hsu/


Sent via Deja.com http://www.deja.com/
Before you buy.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019