Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

array problem

Status
Not open for further replies.

strawberryman

Programmer
Feb 14, 2006
3
0
0
US
I am attempting to make a program in which I need multiple one dimensional arrays. I have succesfully programmed it for the user to input the number of arrays, and it will create that number. Lets say, that is eight arrays. Then, it also places numbers one through eight in the 0-7 spots. Is there an operator that will change to order of the numbers in an array, like moving the first number, to being the last? So my first array is 1,2,3,4,5,6,7,8, then the next one is 2,3,4,5,6,7,8,1 then 3,4,5,6,7,8,1,2;....and so on?
 
> like moving the first number, to being the last?
Something like (assuming 8 elements)
Code:
int temp = a[0];
memmove ( &a[0], &a[1], 7*sizeof(a[0]) );
a[7] = temp;

--
 
you may want to consider using vectors instead of arrays. The STL has plenty of functions that will allow you to move the values where you want them.
The other option is to have those numbers created in that order when you first make the arrays.
something like
//need loop here for making temp arrays
y = numarrays; //makes start value of array
for (int x = 0; x < maxarrays; x++)
{
if ( y > maxarrays)
y = 1;
a[x] = y;
y++
}

Durible Outer Casing to Prevent Fall-Apart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top