Mail Archives: djgpp/1998/04/29/22:02:23
Lennart Marien wrote:
>
> 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
If I understand what you're doing, it shouldn't be that hard. One thing
to
point out is the last line of code in your posting:
*addr_of_buf[10]=0;
If you study your C syntax, you'll catch the bug. What this line says
is:
Assign the value 0 to 11th pointer in your array of pointers. Or
something
like that. Try removing the preceding pointer dereference (*). This
should
fix the problem.
addr_of_buf[ 10 ] = 0;
This means "assign 0 to the 11th element in your array".
Hope this helps.
Michael
- Raw text -