From: Jason Green Newsgroups: comp.os.msdos.djgpp Subject: Re: Pointers to stucts Date: Mon, 29 May 2000 13:55:33 +0100 Organization: Customer of Planet Online Lines: 32 Message-ID: References: <01414368 DOT 9f063b88 AT usw-ex0103-086 DOT remarq DOT com> NNTP-Posting-Host: modem-240.neon.dialup.pol.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: newsg4.svr.pol.co.uk 959605061 15257 62.136.9.240 (29 May 2000 12:57:41 GMT) NNTP-Posting-Date: 29 May 2000 12:57:41 GMT X-Complaints-To: abuse AT theplanet DOT net X-Newsreader: Forte Agent 1.7/32.534 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Dogansmoobs wrote: > typedef struct bitmap > { > int width; > int height; > char *dat; > } bitmap; > bitmap *bmp; That only creates a pointer to a bitmap structure. No memory is allocated for the struct or for the data pointed to by dat. In other words, bmp has some random value and points to some random memory location. You need to allocate some memory for the strucure and then make bmp point to it. Likewise for the dat pointer. > bmp = loadPcxFile("file.pcx"); > > In the loadPcxFile function, it always crashes on the line: > bmp->width = width; > > and also in any function that tries to access the passed pointer > to a bitmap, I get a page fault. This is consistent with you attempting to dereference a pointer without first pointing it at some valid memory location. I suggest to find a good book explaining the relationship between pointers, arrays and memory; then try out a few simple examples to understand this before continuing. You will probably also want to investigate the malloc() and free() functions.