🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: hepnet.lang.c++
Article #1

dynamicaly allocating a two dim. array

#1
From: Bart Trojanowski
Date: Mon, 09 Oct 1995 23:07
33 lines
1289 bytes
I desperately need help.  My assignment is due very soon.

What I need to do is allocate memory for the following....

float array[x][y];

but dinamicaly, ie the user specifies how large it must be.

float = **array; 
x=user_input();
y=user_input();

*array = new (float*) [x];
for (a=0;a<x;x++)
  array[a] = new float [y];

...

for (a=0;a<x;x++)
  delete array[a];
delete *array;

...

how come this works in dos and under windows it gives me a funkey
protection fault.



------------------------------------------------------------------------------
Bart Trojanowski         Carleton University         School O'Computer Science
btrojano@chat.carleton.ca                            ab527@freenet.carleton.ca
------------------------------------------------------------------------------
Technical Details
Message-ID: <DG7ExA.3CG@cunews.carleton.ca>
Path: arc1-ca.pugleaf.net!fnnews.fnal.gov!cunews!wabakimi!btrojano

Show Full Headers
Complete Article Headers
Newsgroups: hepnet.lang.c++,comp.lang.c,comp.lang.c++,cern.c++
Path: arc1-ca.pugleaf.net!fnnews.fnal.gov!cunews!wabakimi!btrojano
From: btrojano@chat.carleton.ca (Bart Trojanowski)
Subject: dynamicaly allocating a two dim. array
X-Nntp-Posting-Host: wabakimi.carleton.ca
Message-ID: <DG7ExA.3CG@cunews.carleton.ca>
Sender: news@cunews.carleton.ca (News Administrator)
Organization: Carleton University
X-Newsreader: TIN [version 1.2 PL2]
Date: Mon, 9 Oct 1995 23:07:58 GMT