473,327 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 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?
thanks!
Sep 7 '06 #1
1 11744
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

5
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)
11
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...
11
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)
6
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...
6
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...
5
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...
0
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
6
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...
3
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.