# coping elements not in array

• 08-04-2008
lord
coping elements not in array
If the user is given an option of inputing a certain amount of int elements (MAX being 9) and then inputs those elements, how can I copy the elements he did NOT put into the array into another array?

For example,
He/She enters 3 then inputs 1, 2, 3

4, 5, 6, 7, 8, 9 is copied into another array.

or

they enter 2 then input 1, 3

2, 4, 5, 6, 7, 8, 9 is copied into another array.

I've tried to use two for loops to accomplish this but I can't figure out the logic. Because depending the users input it seems the logic (the indexes) have to change...

any ideas?
• 08-04-2008
Richie T
I'm confused by your question: are you saying that you have an array of 9 integers in your program, and you want a user to be able to select which values are not copied from the first array to a second array?

Code:

Array 1

0    1    2  3  4  5    6    7    8
-------------------------------------------
| 13 | 27 | 16 | 2 | 9 | 7 | 12 | 66 | 42 |
-------------------------------------------

User selects values 0, 4 and 5

Array 2 becomes

0    1  2    3    4    5
------------------------------
| 27 | 16 | 2 | 12 | 66 | 42 |
------------------------------

• 08-04-2008
whiteflags
If Richie is on the right track, then if you have an array of all the possible items, first, copy as much as you can from the array until you match an excluded item. Then, adjust your indices to skip that element in the array your copying from, but don't advance your position in the array you're copying to.

Keep going until you've passed every excluded item.

Then just copy the rest.