good people of /sci/ i need some coding help. i'm working on a project and i will be using trees, but i have some problem in my code i can't debug
typedef char labeltype;
typedef struct __celltype {
labeltype label;
struct __celltype *first_child;
struct __celltype *next_sib;
struct __celltype *last_child;
int zadnji;
} celltype;
typedef celltype *node;
typedef celltype *Tree;
node lambda;
lambda->zadnji=100; //ERROR
#define LAMBDA lambda
my compiler says that there is an error in the above marked line but i don't understand why. it says expected '=', ',', ';', 'asm' or '__attribute__' before '->' token|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
any help would be apreciated
>>7652405
Have you tried moving the define to above where you first use it?
>>7652415
yeah :/ exact same error
>>7652405
>i
loser
>node lambda;
>lambda->zadnji
lambda is struct, not a pointer to a struct. To access data use "lambda.zadnji" or "(&lambda)->zadnji" not "lambda->zadnji"
>>7652405
Code in C++
lambda is of type node, which is celltype*, therefore, a pointer. you are trying to initialize a member of the struct without allocating memory first.
You need to add
lambda = (celltype*)malloc(sizeof(celltype));
after the definition node lambda;
>>7652441
tried it but again the same error. and btw lambda is not a struct, lambda is a pointer to struct because lambda is node which is pointer to celltype which is struct
>>7652475
>lambda = (celltype*)malloc(sizeof(celltype));
data definition has no type or storage class [enabled by default]|
>>7652475
i tried with (struct __celltype)* instead of celltype* but the same error wtf
>>7652487
make sure that the line is inside int main
this should work
#include <iostream>
using namespace std;
typedef char labeltype;
typedef struct __celltype {
labeltype label;
struct __celltype *first_child;
struct __celltype *next_sib;
struct __celltype *last_child;
int zadnji;
} celltype;
typedef celltype *node;
typedef celltype *Tree;
node lambda;
int main()
{
lambda = (node)malloc(sizeof(celltype));
lambda->zadnji=100;
cout << lambda->zadnji;
cout << sizeof(celltype);
return 0;
}
notice you can replace celltype* with node in the allocation and sizeof(celltype) with 20, since you're renaming celltype with node
>>7652498
yeah tnx a lot :), i don't know how i missed that
>zadnji
yugo detected
>>7652481
U wot m8
>>7652503
haha samo balkan
>>7652447
This. Or even some scripting language.