A89: Re: Re: A C question


[Prev][Next][Index][Thread]

A89: Re: Re: A C question




> Hi!
>
> | I have a question about C.  Lets say I have a sprite and it looks like
> this:
> |
> | static unsigned int block[] = {0xFF,0xC3,0xA5,0x99,0x99,0xA5,0xC3,0xFF};
> |
> | And I wanted to save that to a temporary sprite.  How would I go about
> | storing that sprite into a different sprite.  I tried this:
> |
> | static unsigned int temp[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
> | .
> | .
> | .
> | temp = block;
>
> Simply assigning it wouldn't work in this case, I think.  Try 'memcpy' from
> 'mem.h'.  It would look something like this (although I don't know if the
> 'sizeof' works that way):
>
> memcpy (&temp, &block, sizeof (temp));

<temp> and <block> are both pointers, so the "&" shouldn't be needed. Not too
sure about this though.

Also, sizeof(temp) will return 4, the size of a pointer. In C there is no way of
determining what size an array or matrix is - you have to manage such things
yourself.
In this case it's easy since the sprite will probably have the same fixed amount
of data each time. Just put 16 (if you use ints) or 8 (if you use chars) instead
of sizeof().


 / Niklas Brunlid
Check out Prosit for the TI-89 / TI-92+ at http://prosit.ticalc.org
Random PQF Quote follows:

FABRICATI DIEM, PVNC.
        -- The motto of the Ankh-Morpork City Watch
           (Terry Pratchett, Guards! Guards!)





References: