Posted By: er_willy
acesing to linking structures - 02/23/07 11:08
//basic weapons data
typedef struct
{
char WEAPON_name;
int WEAPON_weigh;
int WEAPON_size;
}WEAPONS;
//fire weapons
typedef struct
{
WEAPONS weapons_str ;
int WEAPON_munition;
int WEAPON_range;
}FIRE_WEAPONS;
FIRE_WEAPONS OBJ_pistol = { WEAPON_munition = 8; WEAPON_range = 800;}
all correct for lite-c, but I not can use the data of the firs structure using the OBJ_pistol.
lite-c give error
example:
OBJ_pistol.weapons_str.WEAPON_weigh = 10;
Posted By: jcl
Re: acesing to linking structures - 02/23/07 15:56
There are two mistakes:
char WEAPON_name; => I suppose you mean char WEAPON_name[..];
FIRE_WEAPONS OBJ_pistol = {..} => FIRE_WEAPONS* OBJ_pistol = {..}
You can create initialized struct pointers, but not initialized structs.
Posted By: FBL
Re: acesing to linking structures - 02/27/07 17:57
You are using the C-script way of initializing strings. Better use str_create()
What you are doing is you create 30 string POINTERS, but they all point to nowhere.
Posted By: er_willy
Re: acesing to linking structures - 02/28/07 11:31
damed damed is again a typo, so sorry , and thanks Firoball
I have litte time, the code what put no is for any game, is a test over test, only for learn the new lite-c. And my englis is short for large questions.
ok I bening again, when fast code, and only the original question of the post:
//If you create a linking strutures, in this example the struc_01 is linking inside of struc_02...
typedef struct
{
var var_struct01;
}struct01;
typedef struct
{
struct01 struct_01;
var var_struct02;
}struct02;
//...if you wanna create initialized struct pointers with linking structures. what is the code??...
//This not give error when compiler, but not work var_struct01 contain 0.
struct02* struct_test ={var_struct01 = 1; var_struct02 = 2;}
//this give error
struct02* struct_test ={{var_struct01 = 1;} var_struct02 = 2;}
struct02* struct_test ={{var_struct01 = 1;}; var_struct02 = 2;}
Posted By: FBL
Re: acesing to linking structures - 02/28/07 17:37
struct02 test;
test.var_struct02 = 2;
test.struct_01.var_struct01 = 1;
Posted By: er_willy
Re: acesing to linking structures - 02/28/07 18:11
yes, thaks for you time. and yes is the best workaround, and I know what this work.
but is posible in the line
struct02* struct_test = ...
@Firoball
I can give to you the adress of my house, if you wanna going to hammer my head.
Posted By: FBL
Re: acesing to linking structures - 02/28/07 18:26
struct02* test;
test = (struct02*)malloc(sizeof(struct02));
test->var_struct02 = 2;
test->struct_01.var_struct01 = 1;