Simple Access to structure element

 
Hi,

only a short basic question.

I create a struct. In the array i only store 1 row (1 element each), how i can access them.

struct my_data_struct
{
   double     field1;   
   int         field2;     
   int         field3;     
};
my_data_struct my_data[];


I can access with

my_data_struct[0].field1




Is it possible to do it only with  "my_data_struct.field1"?

 
ReLor2:
Hi,

only a short basic question.

I create a struct. In the array i only store 1 row (1 element each), how i can access them.



I can access with




Is it possible to do it only with  "my_data_struct.field1"?

my_struct_var = my_struct_arr[0];

my_struct_var.field_1
 
ReLor2:


I can access with

my_data_struct[0].field1


Is it possible to do it only with  "my_data_struct.field1"?

No.

the array name is

my_data_struct my_data[];

so you access it with the array name

my_data[0].field1

Avoid using such similar names, it can be confusing.

 
Keith Watford #:

No.

the array name is

so you access it with the array name

Avoid using such similar names, it can be confusing.

Hi,

sorry you've right, i typed it wrong.

So, is it possbile to acees by 

my_data.field1

instead

my_data[0].field1

?

And by the way, is there a way to prefill the stuct array with datas for the first element ([0]) ?