[Dev-C++] Allocation and deallocation
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Jan M. <jan...@vo...> - 2007-05-10 14:00:19
|
Hello,
I have got two more things about the allocation of pointer types.
I have structure like:
struct list
{
int id;
char *name;
struct list *next;
};
struct list *element;
Should now I do something like:
element = malloc(sizeof(struct(list element));
element->name = malloc(sizeof(strlen("some string here")));
element->next = malloc(sizeof(struct list((;
...main program here...
free(element->next);
free(element->name);
?
And the second thing, more about the alghoritgm of connected list or how is
it called.
The structure above defines an element of such a list. Where there is NULL
in element->next it means it is the last element in the list. And I have
another structure defined like:
typedef struct Queue{
struct bet_list *front;
}Queue;
Queue *q;
I store an adress to the first element in the list in q.
Is this correct? Or is there some more commone and easier way?
Thank you again
Jan Mura
jan...@vo...
|