0
How to copy an array?
I have const char* msg = "123456789"; i want to have that same array in another array.
3 Answers
+ 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;
}
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.
0
Could you write an example program?