Passing a char* to a function

Hi, I have a little bit of an issue here. I've create this char* variables:

char* Menu_1[] = {"Carrera", "Conf. basica", "Conf. avanzada"};
char* Menu_11[] = {"Empezar", "Vueltas","Modo", "Atras"};
char* Menu_12[] = {"Combustible", "Ban.Amarillas", "Atras"};
char* Menu_13[] = {"Atras"};
char* Menu_111[] = {"Pausar", "Vueltas pendientes","Anular"};
char* Menu_actual[];

Depending on the case, I want to pass the function call "actualizar" a particular char* variable, so the function is declare as this:

void actualizar(char* menu[]);

before calling the function I assign the need char* variable, for example like this:

Menu_actual=Menu_1;

And when calling the function I used:

actualizar(Menu_actual);

Doing it this way, I get the following error:

Compilation error: 'Menu_actual' has incomplete type

I've also tried assiging the array as this:

Menu_actual[]=Menu_1[];

And then the error message is:

Compilation error: expected primary-expression before ']' token

Do you know what can be the issue?

Thanks in advance.

Always post all the code. Errors are in the part you did not post.

Take the note that the type of your Menu_1 variable is not char*

Here is a simple code to reproduce the issue:

void setup() {
// put your setup code here, to run once:
}

void loop() {
// put your main code here, to run repeatedly:
char* Menu_1[] = {"Carrera", "Conf. basica", "Conf. avanzada"};
char* Menu_actual[]= {"", "",""};

Menu_actual[]=Menu_1[];
}

This definition is nonsense:

The incomplete array (declared by []) must be initalized at the time of declaration.

And this line is incorrect, you can't assign arrays

Start from reading abour arrays and pointers in C, you code demonstrate that you lack understanding of the topic

OK, the correct syntax for the last code is:

void setup() {
// put your setup code here, to run once:
}

void loop() {
// put your main code here, to run repeatedly:
char* Menu_1[] = {"Carrera", "Conf. basica", "Conf. avanzada"};
char** Menu_actual;

Menu_actual=Menu_1;
}

but without understanding the pointers you can hardly use it

That will still give warnings or errors, depending on the compiler options, because the strings are constant.

void setup() {
  // put your setup code here, to run once:
}

void loop() {
  // put your main code here, to run repeatedly:
  const char* Menu_1[] = {"Carrera", "Conf. basica", "Conf. avanzada"};
  const char** Menu_actual;

  Menu_actual = Menu_1;
}

To the original poster:

void actualizar(char* menu[]);

Should be:

void actualizar(const char** menu);

but note that in either case, the actualizar function does not know how many strings you have in each array.

Issue solved, thanks very much.

Can you recomend me an online resource for understaning pointers?

Last time I learned about then was a long, long time ago, with Dennis M. Ritchie book.... :slight_smile: