468,512 Members | 1,459 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

memcpy integers onto floats

i need to copy N unsigned short number that live in an N-dimensional array onto an equal size array of floats (the original array - unsigned short - is returned by the cfitsio library). can i use memcpy to do that?
i naively attempted to write

float *pixels;
unsigned int *flux;
... malloc-ing and filling up flux[]
pixels = malloc(N*sizeof (float));
memcpy( pixels, (float *) flux, N*sizeof (float));

and it obviously segfaulted. can i do it at all?
Sep 7 '06 #1
1 9228
The prototype of memcpy is .......

void *memcpy(void *dest, const void *src, size_t n);

The memcpy() function copies n bytes from memory area src to memory area dest.

The datatype of both src and dest should be same. So your need will not be fulfilled with memcpy() function.

Instead you manually access each element of the integer array and put it into the float array.
Sep 7 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Jørgen Cederberg | last post: by
11 posts views Thread by redefined.horizons | last post: by
11 posts views Thread by Steve | last post: by
6 posts views Thread by Peter Wuertz | last post: by
6 posts views Thread by BevG | last post: by
5 posts views Thread by Tim | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.