From: jason_hsu AT apexmail DOT com Newsgroups: comp.os.msdos.djgpp Subject: SIGSEGV error when reading a file into an array Date: Sun, 02 Jul 2000 01:35:51 GMT Organization: Deja.com - Before you buy. Lines: 127 Message-ID: <8jm69n$tj0$1@nnrp1.deja.com> NNTP-Posting-Host: 24.18.171.165 X-Article-Creation-Date: Sun Jul 02 01:35:51 2000 GMT X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt) X-Http-Proxy: 1.1 x59.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 Here is the situation: I have a spreadsheet saved as a tab-delimited text data file. I am trying to save the data to a string array. However, I keep getting a SIGSEGV stack fault error. How do I avoid getting this error? I'm sure that someone here has been here before, and I would like to know what it took for you to solve such a problem. Some notes: The text data file is about 2K, and the spreadsheet consists of 10 columns and 26 rows. Here is the code. (You'll want to create a file for "input_numbers_file_name".) #include #include #include void get_data(string file_name) { char ch; int row_num=1, row_num_max=1, col_num=1, col_num_max=1, data_length=1, data_length_max=1; fstream fin1 (file_name.c_str(), ios::in); if (!fin1) { cout << "Unable to open file"; } while (fin1.get(ch)) { if (ch==char(9)) { data_length=1; col_num++; if (col_num>col_num_max) { col_num_max=col_num; } } else if (ch=='\n') { row_num++; col_num=1; } else { data_length++; if (data_length>data_length_max) { data_length_max=data_length; } } } fin1.close(); row_num_max=row_num-1; cout <<"\n"<< row_num_max<<" rows\t"<