Improve company productivity with a Business Account.Sign Up

x
Solved

# Copy from CArray<sVector,sVector> to sVector *ArrayOfVectors

Posted on 2004-09-22
Medium Priority
305 Views
Last Modified: 2010-04-01
Hi,
I have an sVector struct:

typedef t_Vector
{
double Xcoord,
double Ycoord,
double Zcoord
}
and:

CArray<sVector,sVector>              TempVectorsArray;

sVector                                        *ArrayOfVectors;

I need to copy all the element from TempVectorsArray to ArrayOfVectors, but each time
when i get into the copy  i need to copy the data from the TempVectorsArray into a
different place on the ArrayOfVectors,for example:

for(int base_index =0 ; base_index<100; base_index++)
{
// I need to change this line to the correct form - copy from TempVectorsArray to
// ArrayOfVectors[base_index]
ArrayOfVectors[base_index] = TempVectorsArray;   //now it's error of course
}

Thanks a lot:-)
0
Question by:dani333
• 3
5 Comments

Author Comment

ID: 12127957
the correct struct is of course :

typedef t_Vector
{
double Xcoord,
double Ycoord,
double Zcoord
}sVector;

sorry for the mistake.
0

LVL 22

Accepted Solution

NovaDenizen earned 360 total points
ID: 12128146
Something more like this?

int base_index;
...calc base_index here...
int len = TempVectorsArray.length();
int i;
for(i = 0; i < len; i++) {
ArrayOfVectors[base_index + i] = TempVectorsArray[i];
}

This copies all elements from TempVectorsArray into a subrange of ArrayOfVectors starting at index base_index.  Make sure that ArrayOfVectors is allocated to be big enough to contain all elements of TempVectorsArray.

0

Author Comment

ID: 12128287
yes,but do you have another way without looping all the elements in the array?
with pointers , address or something like that?
0

Author Comment

ID: 12128380
Maybe memcpy or ather way....
0

LVL 9

Expert Comment

ID: 12129238
i would not suggest memcpy unless you are sure that sVectors are laid out in contiguous chunk of memory.
0

## Featured Post

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

## Join & Write a Comment Already a member? Login.

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
###### Suggested Courses
Course of the Month11 days, 5 hours left to enroll

#### 608 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.