Is possible to Initialize a variable with an structure type

I mean. Imagine I have:

typedef struct
{ int posx;

  • int posy;*
  • int ancho;*
  • int alto;*
  • String etiqueta;*
    } botones2;

and I define a var

botones2 miboton;

Can I do something like this:

miboton = (30,15, 20, 40, "My Label")

...or do I have to assign values field by field??

Can I do something like this:

Using curly braces instead of parentheses, yes, IF you do it as part of the declaration:

botones2 miboton = {30,15, 20, 40, "My Label"};

Ok, thank very much... I tell you what I am looking for....

I have initialized the buttons as you told me:

botones boton1 = {30,15, 20, 40, "boton1"};
botones boton2 = {30,15, 20, 40, "boton2"};
botones boton3 = {30,15, 20, 40, "boton3"};
botones boton4 = {30,15, 20, 40, "boton4"};

And now I have, a second struct (and a third struct) like that:

typedef struct 
{
  String nzona;
  botones boton[];
} zonas;

typedef struct 
{
  String nzona;
  botones boton[];
} zonas;

typedef struct 
{
  String nsitio; //The name of the site
  zonas zona[5];
} sitio;

sitio misitio;

I want to reference like that... (in fact I am not sure if I have defined the strucs right)

misitio.zona[0].boton[0].posx = 30;

or

misitio.zona[1].nzona = "Texto Zona 1";

and things like that...... but I have 2 main doubts.

1 - Am I defining the structures right? I don't know, but it is like I see something strange.

2 - I would like to fill the structure in the time I declare... but I am not able, I loose myself. Any advise about it? I just "fills" buttons as you told me, but I loose again to zonas and site....

Thank you very mucha.

1 - Am I defining the structures right? I don't know, but it is like I see something strange.

No. When you leave out a value in the braces to define the size of an array, the compiler counts the initializers. You have none, so you will get a zero sized array. Not very useful.

Also, dump the String class before you run out of memory.

2 - I would like to fill the structure in the time I declare... but I am not able, I loose myself.

You should be using arrays of pointers. After defining the botones instances, you can use the instances to populate the array, when you size it properly, with the addresses of the instances.

PaulS:
No. When you leave out a value in the braces to define the size of an array, the compiler counts the initializers. You have none, so you will get a zero sized array. Not very useful.

Also, dump the String class before you run out of memory.
You should be using arrays of pointers. After defining the botones instances, you can use the instances to populate the array, when you size it properly, with the addresses of the instances.

I don¡t mind to fix it .... I am new on it and by now I am avoiding pointers.

Ummm.... so the problem is that I don't write the dimension of the arrays... If I did would it work the struct?