471,047 Members | 1,222 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,047 software developers and data experts.

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 10318
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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.