Advertisement

Linked Lists in C

Started by September 18, 2000 12:50 AM
3 comments, last by cow_in_the_well 24 years, 3 months ago
This compiles fine in CPP but compiled under C it comes up with annyoing errors.

// This is an example linked list
typedef struct NODE_TYP
{
	int id;
	int some_number;
	char some_text[32];
	NODE_TYP *next; // Line 21
} NODE;
 
errors are: D:\Projects\Tilt Table\GSprite.H(21) : error C2061: syntax error : identifier ''NODE_TYP'' D:\Projects\Tilt Table\GSprite.H(22) : error C2059: syntax error : ''}'' So how would i do it in C? thanks ----------------------------- -cow_in_the_well http://cowswell.gda.ods.org/ - Don't Panic -

- Thomas Cowellwebsite | journal | engine video

Since the struct isn''t fully typedef''d yet, you can''t just use "NODE_TYP" to define the pointer on line 21. You need to use the "struct" keywork. In other words...

struct NODE_TYP *next;

That should work, in cpp the typedef doesn''t matter the namespace for NODE_TYP is automatically "typedef"''d, while in regular C it isn''t.

-Omalacon
Advertisement
okay, but when i do this i cannot set next to NULL.

foo->next = NULL; 




D:\Projects\Tilt Table\GSprite.c(25) : error C2115: ''='' : incompatible types


thanks



-----------------------------
-cow_in_the_well

http://cowswell.gda.ods.org/


- Don't Panic -

- Thomas Cowellwebsite | journal | engine video

It''s not safe, but you can use ''void *'' to store pointer
to next element. Then you must cast this pointer to ''NODE *''.

DLife
Its working now- Don''t Panic!

-----------------------------
-cow_in_the_well

http://cowswell.gda.ods.org/


- Don't Panic -

- Thomas Cowellwebsite | journal | engine video

This topic is closed to new replies.

Advertisement