delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/29/20:33:12

From: Vic <tudor AT cam DOT org>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: What's wrong????
Date: Mon, 29 Dec 1997 19:49:10 -0500
Organization: Communications Accessibles Montreal, Quebec Canada
Lines: 20
Message-ID: <34A84506.B7E@cam.org>
References: <34A6E7A9 DOT 35B1E68D AT usa DOT net>
NNTP-Posting-Host: dynappp-144.hip.cam.org
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Rune Lanton wrote:
> *file_buffer = malloc((file_size)+512);
this is your problem. You should read more about pointers in a C book.
if you have this: 
char *p;
p is a pointer to char. It is unitialised, so it can point to any
location in memory.
*p is the VALUE of the variable pointed to.
so if you say p=&variable, *p=5 is equivalent to variable=5;
when you say
 *file_buffer = malloc((file_size)+512);
you malloc some memory then you write the ADRESS of the memory block AT
the ADRESS in memory pointed by p;
that should be
 >> file_buffer = malloc((file_size)+512); << without the asterix.
Hope this was clear enough...


-- 
--> http://www.cam.org/~tudor <--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019