Message-ID: X-MSMail-Priority: Normal X-Priority: 3 To: djgpp AT delorie DOT com Cc: erik2 DOT berglund AT telia DOT com MIME-Version: 1.0 From: "Erik Berglund" Subject: Re: Dinamic allocation Date: Sun, 20 Jun 99 02:19:21 +0100 (DJG) Content-Type: text/plain; charset="ISO-8859-1"; X-MAPIextension=".TXT" Content-Transfer-Encoding: 7bit Reply-To: djgpp AT delorie DOT com Gustavo Niemeyer wrote: > 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. The allocation seems right, but I think the declaration should be "char *spans", and the data access later down below in your program code should look something like: data = spans[MAXWIDTH * y + x]; In this way, the compiler thinks spans is a simple char vector, but that's ok, the multiplication will make it work anyway. Hope this helps, Erik