0

How to copy an array?

I have const char* msg = "123456789"; i want to have that same array in another array.

27th Jun 2016, 1:00 PM
Garme Kain
Garme Kain - avatar
3 Réponses
+ 1
#include <string.h> int main() { char* newarr = new char[strlen(msg)]; unsigned i = 0; while(newarr[i++] = *msg++); msg -= i; cout << newarr; return 0; }
27th Jun 2016, 9:21 PM
Garme Kain
Garme Kain - avatar
0
One, it depends from where and two, to where. Be it from main function to another, then use pointers, and if its another copy of the array you want then you have got to move contents one by one to respective indexes.
27th Jun 2016, 1:27 PM
David Warch
David Warch - avatar
0
Could you write an example program?
27th Jun 2016, 4:10 PM
Garme Kain
Garme Kain - avatar