if this makes a difference, the way i am doing the list is backwards, so when i want to add something to it, i create a new one in the function, then add the given one (which could be NULL or an actual list) to the next, then return the new one
It's not that. Your very first line of code crashed it -- it never had a chance to crash anywhere else
Your linked list function should actually work if you just set the first node to NULL. You don't need pointers to pass client_socket_fd though, just a plain int will be fine.
That's wrong. Now there's no way to tell when the list's empty, and have a garbage blank node at the end of your list that might print garbage or crash.
Could you try what I suggested before instead? Sometimes it feels like I'm talking to a wall here
The exact same way you were using it in the first place. Pointers don't do anything mystical. If you pass NULL into your add_client function, you'll get NULL in your add_client function. When you set current->next to it, you're setting it to NULL.
They're just variables. You can copy them around just like you would a float or an int or a structure. The only time pointers do anything special is when you use their contents with the -> operator, the * operator, or the [] operator.
Last edited by Corona688; 03-31-2011 at 05:45 PM..
Hi, I am programming in kernel, and I want to use a double linked list that holds infos that every process could access and modify THIS list. So, I suppose it is a 'global' variable since every process(thread) can reach it, I am wondering where to put it? by changing some of the kernel files? (1 Reply)
can someone provide an example of a struct linked list, where it has strings as its values, and then how do I check if a specific string (say called buffer) exists in the list of structs?
i dont understand how to make a copy of it to check with
this is what i have
... (0 Replies)
i have a linked list set up like
typedef struct client_list {
char *client_name;
int client_socket_fd;
struct client_list *next;
} client;
client *client_list=NULL;
before adding to the list i check if it already exists, only if it does not then i add
if (client_list==NULL... (1 Reply)