delorie.com/archives/browse.cgi | search |
From: | Antonius Steinkamp <Antonius DOT Steinkamp AT t-online DOT de> |
Newsgroups: | comp.os.msdos.djgpp |
Subject: | Re: Dinamic allocation |
Date: | Sat, 19 Jun 1999 03:33:55 +0200 |
Organization: | T-Online |
Message-ID: | <376AF383.E98318C6@t-online.de> |
References: | <LOBBKLEPLBKLOKFELHOIEELBCCAA DOT djgpp AT niemeyer DOT net> |
Mime-Version: | 1.0 |
X-Trace: | news04.btx.dtag.de 929756118 29812 04473446-0001 990619 01:35:18 |
X-Complaints-To: | abuse AT t-online DOT de |
X-Sender: | 04473446-0001 AT t-online DOT de |
X-Mailer: | Mozilla 4.5 [de]C-DT (Win95; I) |
X-Accept-Language: | de |
Lines: | 32 |
To: | djgpp AT delorie DOT com |
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Reply-To: | djgpp AT delorie DOT com |
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 |