Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > How to make two-dimensional array put 'new' to use in C++?

Reply
Thread Tools

How to make two-dimensional array put 'new' to use in C++?

 
 
chajs226@gmail.com
Guest
Posts: n/a
 
      01-06-2007
Hi everyone.. I'm doing programing a maze problem.
I want to make a maze(array[5][7]) that use two-dimensional array...

but I don't know this...

{
int *a[7];
a[7] = new int [5];
}

this is result in segmentation error


help me... Thanks.

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      01-06-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi everyone.. I'm doing programing a maze problem.
> I want to make a maze(array[5][7]) that use two-dimensional array...
>
> but I don't know this...
>
> {
> int *a[7];
> a[7] = new int [5];
> }
>
> this is result in segmentation error


See FAQ.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
 
fungus
Guest
Posts: n/a
 
      01-06-2007
(E-Mail Removed) wrote:
> {
> int *a[7];
> a[7] = new int [5];
> }
>
> this is result in segmentation error
>


When you create a[7] then elements are
in the range 0 to 6. "7" is past the end
of the array.

--
<\___/>
/ O O \
\_____/ FTB. For email, remove my socks.


Were judging how a candidate will handle a nuclear
crisis by how well his staff creates campaign ads.
Its a completely nonsensical process.
 
Reply With Quote
 
Sean Fritz
Guest
Posts: n/a
 
      01-06-2007
fungus wrote:

> (E-Mail Removed) wrote:
>> {
>> int *a[7];
>> a[7] = new int [5];
>> }
>>
>> this is result in segmentation error
>>

>
> When you create a[7] then elements are
> in the range 0 to 6. "7" is past the end
> of the array.
>


Definitely have to be careful with array ranges in C++, most compilers won't
give you an error if you try to go outside the index.
 
Reply With Quote
 
Salt_Peter
Guest
Posts: n/a
 
      01-06-2007

(E-Mail Removed) wrote:
> Hi everyone.. I'm doing programing a maze problem.
> I want to make a maze(array[5][7]) that use two-dimensional array...
>
> but I don't know this...
>
> {
> int *a[7];
> a[7] = new int [5];
> }
>
> this is result in segmentation error
>
>
> help me... Thanks.


there are 7 numbers from 0 to 6 and 7 isn't one of them.

 
Reply With Quote
 
David Harmon
Guest
Posts: n/a
 
      01-06-2007
On 5 Jan 2007 21:06:10 -0800 in comp.lang.c++, "(E-Mail Removed)"
<(E-Mail Removed)> wrote,
>Hi everyone.. I'm doing programing a maze problem.
>I want to make a maze(array[5][7]) that use two-dimensional array...


Avoid 'new' and bare naked arrays in application-level code.

std::vector< std::vector<int> > array(5, std::vector<int>(7));


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
FAQ 5.9 How can I make a filehandle local to a subroutine? How do I pass filehandles between subroutines? How do I make an array of filehandles? PerlFAQ Server Perl Misc 0 01-12-2011 11:00 PM
why does the following with Queue, q.put('\x02', True) not put itin the queue? Gabriel Rossetti Python 3 04-25-2008 03:41 PM
How does one make use of sub files to make DVD? Bun Mui DVD Video 0 05-21-2006 03:24 PM
How does one make use of sub files to make DVD? Bun Mui Computer Support 0 05-21-2006 03:09 PM



Advertisments