unable to update array

 

Hello,

I am trying to write a function that will take an array and a value as input and output an array, the idea is to shift all the values and have the scalar input be the 0th element of the output, an "updater" function.

I simplified my function to a ridiculous level to try to figure out why it wasn't creating the changes I expected. My guess is the problem (which is that each time I try to apply this function it doesn't seem to change my array at all) has to do with where I've put the array itself and the calls.

Here is my current code (like I said I really simplified the function):

string poppush(string A[6], string New)

{

string Aprime[6];

Aprime[1]=A[0];

Aprime[2]=A[1];

Aprime[3]=A[2];

Aprime[4]=A[3];

Aprime[5]=A[4];


Aprime[0] = New;

return(Aprime);

}

int init() {

string p[6]={"a","b","c","d","e","f"};

poppush(p,"z");

Alert(p[0]); }

.....



I tried having the array p be global, at the same level as the function, but that didn't do anything either, I figured since the function call didn't have access to it from init (or start?).

Please help!

 

with

Aprime[1]=A[0];
Aprime[2]=A[1];

you're overwriting [1] before shuffling it along. try

 
Aprime[5]=A[4];
Aprime[4]=A[3];
(oops - sorry - pressed wrong button for SRC!)
 

also try

void poppush(string& A[6], string New)

rather than

string poppush(string A[6], string New)

(that's *TWO* changes in that line) as

A) you're not using the returned value and

B) you're trying to update array in situ

 

(DOH! why don't I read the post properly before replying?)

use

A[5]=A[4];
A[4]=A[3];

and ignore Aprime and ignore return

 

Thanks!

This worked, I also found that making a variable global and doing

m = m-p;

seems to create the behavior I'm looking for. I'm going to test them both out to see if one is better or has subtle consequences.

Thanks again!

Reason: