delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/06/24/13:21:59

Message-ID: <33AB8C68.C0@fiveg.com>
Date: Sat, 21 Jun 1997 01:10:16 -0700
From: Dion Barrier <webmaster AT fiveg DOT com>
Reply-To: webmaster AT fiveg DOT com
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Allocation with pointer arrays and how to use them once I have.
References: <33AA0FAA DOT 7E19 AT fiveg DOT com> <33AAA41B DOT 7884 AT eev DOT e-technik DOT uni-erlangen DOT de>
NNTP-Posting-Host: 204.202.48.65
Organization: Europa Communications Inc. [Portland, OR]
Lines: 85
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Schuster wrote:
> 
> Hi Dion!
> I'm not quite sure if the following helps, but give it a chance
> (though I tested it with a little program )...
> 
> Try changing
> >// global storage buffer
> >char    *wordBuffer[50];
> to
> char **wordbuffer;
> wordbuffer = new char* [50];
> 
> Why don't you use the String class?
> I always do (if I write in C++ ), it's much easier.
> 
> Hope this helps.
> 
> Michi
> **********************************************
> Michael Schuster
> E-mail: Schuster AT eev DOT e-technik DOT uni-erlangen DOT de
> Lehrstuhl fuer Elektrische Energieversorgung
> http://www.eev.e-technik.uni-erlangen.de/

Thanks Michi,

I had to do a couple modifications to the above in order to get it to
work but you got me started on the right track.  Another person's 
reply filled in a very important piece of the puzzel.  And with the 
information provided by you two I figured it out.  Thank you and in-case 
you're reading this, thank you Günther.  If you're wondering what I 
ended up with here it is:

____________________________

char	**wordBuffer[10000];

void SomeFunction(void)
{                         
	char	tmpBuffer[128];
	int		i = 0;
	
	fstream fin("test.txt", ios::in | ios::nocreate);
	
	if(!fin.is_open())
	{
		cerr << "unable to open file.... exiting";
		exit(1);
	}
	
	do
	{
		fin >> tmpBuffer;    
	
		*wordBuffer[i] = new char [strlen(tmpBuffer) + 1];
		strcpy(*wordBuffer[i], tmpBuffer);
	
		cout << *wordBuffer[i] << ' ';
		i++;
    } while(!fin.eof());

	fin.close();
}

_________________________________

Thanks again,
Dion

- Raw text -


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