Re: fread choking on binary file

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Fran D <FranD@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Are you sure you mean &Image.Print.pData (the ampersand in front)
rather than Image.Print.pData (without ampersand) ? If pData is a
pointer, you probably want to read into the buffer pointed to by
pData, rather than into the memory address occupied by pData
variable itself.

If that's not it, show how the memory for Image.Print.pData is
allocated.

Yes, both of you are correct. The ampersand in front of
Image.Print.pData was incorrect.

I removed it and now the pointer to the buffer is assigned to
0x00000000, which I guess is OK...I've just never seen it assigned to
0 before.

Are you saying Image.Print.pData is NULL? If this is the case, I'm not
sure how you expect the call to work. You are supposed to allocate some
memory for the data, store the pointer to this memory in
Image.Print.pData (at which point it certainly stops being NULL), then
pass the pointer to fread.

If I understood your last question correctly, I allocate the memory
for the whole Image.Print structure with:

memset(&Image.Print, 0, sizeof(Image.Print));

memset does not allocate any memory, it just fills existing memory.
Image is probably a stack (automatic) variable, so the memory for the
structure itself is allocated when you declare it. But the structure
only contains a pointer to the actual memory buffer, and memset
helpfully sets this pointer to NULL.

With all due respect, I suggest you go back to basics and review your
favorite C 101 textbook.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


.



Relevant Pages

  • [PATCH 2/6] staging/trivial: fix typos concerning "access"
    ... Constant character string to name this pool. ... @buffer: Pointer to the block of memory to use. ...
    (Linux-Kernel)
  • Re: buffer...
    ... In the case of that function, the buffer can be anything ... Note that the name of an array variable with no is a pointer to the first ... meaning to the bytes stored in a particular memory block. ...
    (microsoft.public.vc.mfc)
  • Re: Is this math test too easy?
    ... > communications glitch; one of the more laughable cartoons ... it was loaded into physical memory and, ... > Or one can interpret the character string as one of the values ... A pointer to an integer? ...
    (sci.math)
  • Re: grow list by tail, pointer example recipe -- please comment
    ... manufacturing a pointer with that address. ... the next cons cell. ... believe these lists are in consecutive memory locations. ...
    (comp.lang.lisp)
  • Re: some unanswered questions on C
    ... A pointer variable that's never been given a value. ... you don't know what memory you're modifying. ... >what i want to ask is that when i declare my buffer for fgets as ... "char *buffer" creates a pointer, ...
    (comp.unix.programmer)