[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y / ] [Home]
4chanarchives logo

good people of /sci/ i need some coding help. i'm working on a project and i


Thread replies: 17
Thread images: 3

File: C.sh-600x600.png (32KB, 600x600px) Image search: [Google] [Yandex] [Bing]
C.sh-600x600.png
32KB, 600x600px
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
>>
File: BE IMPORTANT.jpg (112KB, 612x792px) Image search: [Google] [Yandex] [Bing]
BE IMPORTANT.jpg
112KB, 612x792px
>>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;
>>
>>>/g/
>>>/g/
>>>/g/
>>
>>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
>>
File: 1445512042214.jpg (44KB, 233x217px) Image search: [Google] [Yandex] [Bing]
1445512042214.jpg
44KB, 233x217px
>>7652481
U wot m8
>>
>>7652503
haha samo balkan
>>
>>7652447
This. Or even some scripting language.
Thread replies: 17
Thread images: 3
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y / ] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
If a post contains illegal content, please click on its [Report] button and follow the instructions.
This is a 4chan archive - all of the content originated from them. If you need information for a Poster - you need to contact them.
This website shows only archived content and is not affiliated with 4chan in any way.
If you like this website please support us by donating with Bitcoin at 1XVgDnu36zCj97gLdeSwHMdiJaBkqhtMK