473,657 Members | 2,394 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 1318

"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.9129 5
$oN2.40286@edtn ps84:

"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*******@user sDOTsf.net> wrote in message
news:RoYyb.3917 27$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
3281
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
1321
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
2700
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
7235
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, two aspects which I want to incorporate into my program eventually. That aside, my most pressing problem right now is how to get rid of the newline in the input when I use fgets(). Now I have looked around on the net, not so much in this group...
1
2039
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 root pointer) not be null. /* LINKED LIST DEFINITIONS */ typedef struct a_fnode {
9
2192
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 simple array, to pass to a range constructor for a const vector. Here is some demonstration code: #include <iostream> using namespace std;
24
3439
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 declared an array as: char *stringArray = {"one","two","three","a"}; When I pass the array using:
11
1620
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 different new sizes? AFAIR, realloc with a bigger size must return the new address, or NULL if it fails. I was wondering, what happens when you ask realloc to shrink the allocated space? Will it free the remaining memory or not?
4
1856
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 pointed to returns void and the actual function that returns the pointer: void* getState(CString myString);
3
1849
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 index through a out parameter. The issue is that the out parameter is not being updated. If I return the position to the caller (instead to use a out parameter) all is ok.
0
8420
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8516
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6176
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5642
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
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 we have to send another system
2
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.