472,986 Members | 2,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,986 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 11565
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

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

Similar topics

by: Jørgen Cederberg | last post by:
Hi, using Python 2.2.1 on Windows and QNX I'm having trouble understandig why int() raises a ValueError exception upon converting strings. >>> int('-10') -10 >>> int('10') 10 >>> int(10.1)
by: redefined.horizons | last post by:
I'm still pretty new to Python. I'm writing a function that accepts thre integers as arguments. I need to divide the first integer by te second integer, and get a float as a result. I don't want...
by: Steve | last post by:
I'm trying to create a list range of floats and running into problems. I've been trying something like: a = 0.0 b = 10.0 flts = range(a, b) fltlst.append(flts)
by: Peter Wuertz | last post by:
Hi, I'm writing a C module for python, that accesses a special usb camera. This module is supposed to provide python with data (alot of data). Then SciPy is used to fit the data. My question...
by: BevG | last post by:
Can someone explain the output I'm getting from the following 2 code portions? In the first, I've used n and sizeOfArrays as long doubles, and in the second I've made sizeOfArrays an integer, as this...
by: Tim | last post by:
How do I memcpy from a pointer to an array of floats in python? I get errors: NameError: global name 'row' is not defined I want to be able to get the row array element. In C I would normally...
by: Matthieu Brucher | last post by:
2008/11/5 L V <somelauw@yahoo.com>: Hi, I don't think the Python developers list is th best list to post this kind of question. What version of Python did you use for this test? Matthieu
by: Bytes21 | last post by:
Hello, I am trying to write a program that reads the first line of a variable size file i.e. 77 2.45 3 1.75 2 3.78 5 8.96 11 23.56 3 5.68 3 1.58 7 5.55 and return an array with its...
by: nigelmercier | last post by:
I'm trying to do a calculation that should be simple, but I keep getting a spurious answer of zero. It involves the rate of fuel use of an engine, the formula I'm using is: Rate of fuel use = (RPM...
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.