473,505 Members | 15,381 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple pointer question (:)

J
Hi,

I have an array:

double *array = new double[50];
Well, I have 2 actually.
double *array2 = new double[50];
Say 'array' is poulated with 'doubles'. How do I copy all of array's values
into 'array2'?


TIA,
-- JA
Jul 22 '05 #1
5 1307

"J" <ni********@gl.gl> wrote in message
news:Xn**********************@130.215.36.210...
Hi,

I have an array:

double *array = new double[50];
Well, I have 2 actually.
double *array2 = new double[50];
Say 'array' is poulated with 'doubles'. How do I copy all of array's values into 'array2'?


TIA,
-- JA


memcpy(array2, array, 50 * sizeof(double));
Jul 22 '05 #2
J
Thanks my friend, totally forgot memcpy. (Haven't programmed in awhile!!)
- JA
"Thomas Wintschel" <th******@telus.net> wrote in news:PHTyb.91295
$oN2.40286@edtnps84:

"J" <ni********@gl.gl> wrote in message
news:Xn**********************@130.215.36.210...
Hi,

I have an array:

double *array = new double[50];
Well, I have 2 actually.
double *array2 = new double[50];
Say 'array' is poulated with 'doubles'. How do I copy all of array's

values
into 'array2'?


TIA,
-- JA


memcpy(array2, array, 50 * sizeof(double));


Jul 22 '05 #3

"J" <ni********@gl.gl> wrote in message
news:Xn**********************@130.215.36.210...
Hi,

I have an array:

double *array = new double[50];
Well, I have 2 actually.
double *array2 = new double[50];
Say 'array' is poulated with 'doubles'. How do I copy all of array's values into 'array2'?


std::copy(array, array + 50, array2);

This assumes that 'array' and 'array2' each have at least
50 elements, and that all elements of 'array' have valid
values.

'std::copy()' is declared by <algorithm>.

-Mike
Jul 22 '05 #4
Thomas Wintschel wrote:
"J" <ni********@gl.gl> wrote in message
news:Xn**********************@130.215.36.210...
Hi,

I have an array:

double *array = new double[50];
Well, I have 2 actually.
double *array2 = new double[50];
Say 'array' is poulated with 'doubles'. How do I copy all of array's
values
into 'array2'?



memcpy(array2, array, 50 * sizeof(double));

Hmm...whats memcpy doing in a c++ forum :-)
Jul 22 '05 #5

"Roy Varghese" <rv*******@usersDOTsf.net> wrote in message
news:RoYyb.391727$Tr4.1147654@attbi_s03...
Thomas Wintschel wrote:
"J" <ni********@gl.gl> wrote in message
news:Xn**********************@130.215.36.210...
Hi,

I have an array:

double *array = new double[50];
Well, I have 2 actually.
double *array2 = new double[50];
Say 'array' is poulated with 'doubles'. How do I copy all of array's


values
into 'array2'?



memcpy(array2, array, 50 * sizeof(double));

Hmm...whats memcpy doing in a c++ forum :-)


memcpy() is a standard C++ library function.

-Mike
Jul 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
3252
by: lokman | last post by:
Hi, In the following code, can someone tell me the difference between *p++ and p++ ? I can see both achieve the same result. Thanks a lot !
7
1308
by: cppaddict | last post by:
The following code compiles but errors at runtime: int main() { std::string* str; str->insert(0,"test"); std::cout << *str; } Why does this not work? How can I fix it?
11
2676
by: JKop | last post by:
Take the following simple function: unsigned long Plus5Percent(unsigned long input) { return ( input + input / 20 ); } Do yous ever consider the possibly more efficent:
5
7224
by: Rob Somers | last post by:
Hey all I am writing a program to keep track of expenses and so on - it is not a school project, I am learning C as a hobby - At any rate, I am new to structs and reading and writing to files,...
1
2026
by: Tim | last post by:
I can't seem to figure out why this very simple linked list wont build.. I mean, there is no intelligence, just add to end. Anyway, please let me know if something i can do will make head (the...
9
2177
by: shaun | last post by:
Dear all, I realized an error in a previous post, I reproduce it here because I'm still not sure how to solve it: I want to make a templated function which points to one-past-the-end of a...
24
3402
by: Michael | last post by:
Hi, I am trying to pass a function an array of strings, but I am having trouble getting the indexing to index the strings rather than the individual characters of one of the strings. I have...
11
1604
by: Sensei | last post by:
I'm sorry to always bother you guys on simple C topics... but here again I go :) What does the standard C99 (and if you have knowledge, pre-C99 also) say about the behavior of realloc() on...
4
1845
by: Jeffrey Spoon | last post by:
Hello, I am trying to make a simple function that returns a pointer to another function. In my header file I've declared my function pointer: void (*pStateFunction) (void); //assume the function...
3
1835
by: nembo kid | last post by:
I have an issue with a simple function that has to make a linear search for a key into an array. If the key is found in the array, the function it has to return 1 to the caller and pass array...
0
7216
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7303
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.