1

I have 3 arrays with ints (enums):

static int *openEnv[] = {INGMenuItemLogon,INGMenuItemSpace,INGMenuItemAppointment,INGMenuItemInfo,INGMenuItemSettings};
static int *closedEnv[] = {INGMenuItemLogoff,INGMenuItemSpace,INGMenuItemOverview,INGMenuItemAccounts,INGMenuItemTransfer,INGMenuItemAnalyse,INGMenuItemAppointment,INGMenuItemInfo,INGMenuItemSettings};
int *currentEnv[];

if the user taps on a button i want the currentEnv to change to the openEnv or closedEnv

- (void) tap
{
    if( closed ) currentEnv = closedEnv;
    else currentEnv = openEnv;
}

But this gives a build errors. openEnv and closedEnv have 2 different sizes, what should i do to copy it? What can i do so that it makes a reference or copy to its static array?

4
  • stackoverflow.com/questions/4355556/… Commented Apr 25, 2013 at 10:43
  • 1
    @rptwsthi - I don't think its the same Commented Apr 25, 2013 at 10:46
  • Those are not arrays of enums, they are arrays of pointers to ints. Commented Apr 25, 2013 at 10:52
  • 1
    Please revise your question. Are all tags really appropriate? At least decide on the used language! Commented Apr 25, 2013 at 13:29

3 Answers 3

2

Try this:

static int *openEnv[] = {INGMenuItemLogon,INGMenuItemSpace,INGMenuItemAppointment,INGMenuItemInfo,INGMenuItemSettings};
static int *closedEnv[] = {INGMenuItemLogoff,INGMenuItemSpace,INGMenuItemOverview,INGMenuItemAccounts,INGMenuItemTransfer,INGMenuItemAnalyse,INGMenuItemAppointment,INGMenuItemInfo,INGMenuItemSettings};
//int *currentEnv[];
int **currentEnv;

- (void) tap
   {
     if( closed ) 
        currentEnv = closedEnv;
     else 
        currentEnv = openEnv;
   }
Sign up to request clarification or add additional context in comments.

2 Comments

how can i get an int out the array then, currentEnv[0] gives Statement requires expression of integer type ('int *' invalid)
BTW: I supposed you wanted to have an array of pointers, if you need an array of integers so do it like Martin R said.
1

You have declared arrays of pointers to int. Correct would be

static int openEnv[] = {INGMenuItemLogon,INGMenuItemSpace,INGMenuItemAppointment,INGMenuItemInfo,INGMenuItemSettings};
static int closedEnv[] = {INGMenuItemLogoff,INGMenuItemSpace,INGMenuItemOverview,INGMenuItemAccounts,INGMenuItemTransfer,INGMenuItemAnalyse,INGMenuItemAppointment,INGMenuItemInfo,INGMenuItemSettings};

(without the star *) to declare arrays of int, and

int *currentEnv;

as pointer to int. Then you can assign e.g. currentEnv = openEnv so that currentEnv points to the elemens of openEnv.

1 Comment

+1 supposed that OP wanted to have an array of integers instead of array of pointers to integers :)
1

Just use: int ** currentEnv = <the array>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.