goon12
03-02-2004, 04:17 PM
Hi - I have been looking at this all day causing segfaults and infinite loops...
I have this inside of a function
while( fread(read, 1, sizeof(SERVER), listfile) )
{
newNode = (S_LIST *)malloc(sizeof(S_LIST));
memcpy(newNode, read, sizeof(SERVER));
if( start == NULL )
{
start = newNode;
}
else
{
newNode->next = end;
end = newNode;
}
}
start->next = end;
That function then returns start, which I am able to use to loop through and show some information. Now here is the definition of type S_LIST
typedef struct server_list{
char name[100];
char addr[50];
int port_no;
int ports[50][50];
struct server_list *next;
struct server_list *prev;
} S_LIST;
I have been trying all day to get that to become a doubly linked list - and I can't seem to do it. The closest I can get is under "start->next = end" I put "end->prev = start" and the output looks like this
Server 0x8053e50 Address: 66.189.35.129 next = 0x8058dc0 prev = (nil)
Server 0x8058dc0 Address: 209.51.247.230 next = 0x8056608 prev = 0x8053e50
Server 0x8056608 Address: 209.51.247.235 next = (nil) prev = (nil)
My question is:
How to I turn that into a doubly linked instead of a singly linked list? :confused:
I have this inside of a function
while( fread(read, 1, sizeof(SERVER), listfile) )
{
newNode = (S_LIST *)malloc(sizeof(S_LIST));
memcpy(newNode, read, sizeof(SERVER));
if( start == NULL )
{
start = newNode;
}
else
{
newNode->next = end;
end = newNode;
}
}
start->next = end;
That function then returns start, which I am able to use to loop through and show some information. Now here is the definition of type S_LIST
typedef struct server_list{
char name[100];
char addr[50];
int port_no;
int ports[50][50];
struct server_list *next;
struct server_list *prev;
} S_LIST;
I have been trying all day to get that to become a doubly linked list - and I can't seem to do it. The closest I can get is under "start->next = end" I put "end->prev = start" and the output looks like this
Server 0x8053e50 Address: 66.189.35.129 next = 0x8058dc0 prev = (nil)
Server 0x8058dc0 Address: 209.51.247.230 next = 0x8056608 prev = 0x8053e50
Server 0x8056608 Address: 209.51.247.235 next = (nil) prev = (nil)
My question is:
How to I turn that into a doubly linked instead of a singly linked list? :confused: