delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/29/22:24:46

From: qballlives AT aol DOT com (QBallLives)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: malloc?
Lines: 80
Message-ID: <1998042923052100.TAA25890@ladder01.news.aol.com>
NNTP-Posting-Host: ladder01.news.aol.com
Date: 29 Apr 1998 23:05:21 GMT
Organization: AOL http://www.aol.com
References: <6i7v0o$ns6$1 AT news DOT metronet DOT de>
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

>
>Hi!
>I have a severe problem which is bothering since
>hours.What Iīm trying o do is the following in pseudo
>code:(the struct PCXHeader is declared before)
>
>int handle;
>short width,heigth;
>void addr_of_buf;
>
>void readheaderPCX(char *fd,struct PCXHeader *header)
>/*this function works*/
>{
>handle=open(fd,O_BINARY);
> read(handle,header,sizeof(*header));
>};
>
>void readln(char *buffer,short width)
>{
>/*buffer is a pointer to a variable like 'char buffer[width]'*/
>[.....]
>/*The routine reads data bytes and expands them into buffer
>until buffer is full*/
>};
>
>void loadpcx(int x, int y, char *fd)
>{
>struct PCXHeader h;
>readheader(fd,&h);
>/*works*/
> width=h.x2-h.x1;
>  heigth=h.y2-h.y1;
>/*donīt know if you understand, but it works*/
>addr_of_buf=malloc(width);
>[...]
>/*the program reads data line and shows it....*/
>};
>
>
>Hope this wasnīt confusing if so here is it in text:
>I read some information from an 8Bit-PCX file to compute the height and the
>width of
>the picture.Then a buffer is allocated to contain one line of a pic.Since
>itīs an
>8Bit file the variable would look like char buffer[width].
>A Pointer addr_of_buf should contain the address of the allocated memory
>using malloc:
>addr_of_buf=malloc(width);
>Now a function called readln reads WIDTH bytes from the file and puts them
>into the buffer.My question is actually about malloc hy doesnīt it work?
>I always get an error message if I try to address my memory like this:
>
>*addr_of_buf[10]=0;
>
>He tells me of some unary operator *?
>What can I do?
>
>Thanks in advance!!!!!
>cu
>
>
>

Believe it or not... I've had trouble with that too.... DOH!

It's because I learned from realmode code.... and 320x200 was assumed.... and
the header info was always just skipped through....

I should give it another shot... because I do load/save games in stuff.... and
that uses various types of info.. for my purposes... but when I tried
extracting width and height from a pcx, I got errors...

In other words: Good question!



Jim the loiterer
aloiterer AT juno DOT com
http://members.xoom.com/JimMcCue/index.htm
(Jim the loiterer's PC games, programming, & stuff...)

- Raw text -


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