delorie.com/archives/browse.cgi | search |
X-Authentication-Warning: | niemeyer.net: Host 200.230.186.179-as.acessonet.com.br [200.230.186.179] claimed to be computer |
From: | "Gustavo Niemeyer" <djgpp AT niemeyer DOT net> |
To: | <djgpp AT delorie DOT com> |
Subject: | RE: Dinamic allocation |
Date: | Sat, 19 Jun 1999 14:55:38 -0300 |
Message-ID: | <LOBBKLEPLBKLOKFELHOIAELGCCAA.djgpp@niemeyer.net> |
MIME-Version: | 1.0 |
X-Priority: | 3 (Normal) |
X-MSMail-Priority: | Normal |
X-Mailer: | Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) |
X-MimeOLE: | Produced By Microsoft MimeOLE V5.00.2314.1300 |
In-Reply-To: | <376AF383.E98318C6@t-online.de> |
Importance: | Normal |
Reply-To: | djgpp AT delorie DOT com |
X-Mailing-List: | djgpp AT delorie DOT com |
X-Unsubscribes-To: | listserv AT delorie DOT com |
Thank you for your answer Antonio! I had to change some thing in your code to compile it. Code now looks like this: char **spans; spans = (char **) malloc(MAXHEIGHT); for(i=0; i<MAXHEIGHT; i++) spans[i] = (char *) malloc(MAXWIDTH); But it isn't working anyway! I tried to delete the second line but it didn't work again... By the way, I can't understand why the old code isn't working... Thank you! Gustavo Niemeyer -----Original Message----- From: Antonius Steinkamp [mailto:Antonius DOT Steinkamp AT t-online DOT de] Sent: Sexta-feira, 18 de Junho de 1999 22:34 To: djgpp AT delorie DOT com Subject: Re: Dinamic allocation try to allocate this way spans = (char*)malloc(MAXHEIGHT) for ( int i=0; i<MAXHEIHT; i++) { spans[i] = (char)malloc(MAXWIDTH); } this is not tested but should work (aka indexes) Gustavo Niemeyer schrieb: > > Hi there! > > I think I'm doing some thing wrong here. > > When I try to hard code an array like this: > > char spans[MAXHEIGHT][MAXWIDTH]; > > So the program runs ok. But when I try to > use dinamic memory allocation like this: > > char **spans; > spans = (char **) malloc(MAXWIDTH*MAXHEIGHT*sizeof(char)); > > When I run the program it prints a General > protection fault error, pointing to a loop > that accesses the array. > > Probably is something I'm missing... isn't it? > > Thank you > > Gustavo Niemeyer
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |