how to copy an array in C

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
tzzx
New poster
Posts: 14
Joined: Thu May 15, 2003 6:29 am

how to copy an array in C

Post by tzzx »

in pascal ,i could write simply : a:=b
but how in c
hank
Experienced poster
Posts: 146
Joined: Mon Feb 04, 2002 2:00 am
Location: VCORE.

Post by hank »

for example:
[cpp] int a[10],b[10];
.......
b=a; // copy a to b
[/cpp]
Maxim
New poster
Posts: 38
Joined: Tue Aug 27, 2002 12:36 am
Location: Croatia
Contact:

Post 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
Post Reply

Return to “C++”