Page 1 of 1

how to copy an array in C

Posted: Sun May 25, 2003 1:02 pm
by tzzx
in pascal ,i could write simply : a:=b
but how in c

Posted: Sun May 25, 2003 2:55 pm
by hank
for example:
[cpp] int a[10],b[10];
.......
b=a; // copy a to b
[/cpp]

Posted: Sun May 25, 2003 10:43 pm
by Maxim
Well, you could include "string.h" (cstring), and do something like this:
[cpp]#include <cstring>
...
int a[10], b[10];
...
memcpy(b, a, sizeof a); //copy a to b[/cpp]
But you should be careful about third parameter.

Maxim