i want to append a node in the linked list
when i append this as

struct node*p;
p=NULL;
append(p,1);

where function is declared as

append(struct node*q int num)

i append three node,
after this i call the function for counting the node,
i get the total no node is 0, while i have appended the node.
what is the error...
please help me...

This issue is simple: you are trying to append() a NULL pointer, which (depending on how your append() function works) will either return an error or silently fail, as a NULL node is the same as not appending a node at all.

In order to actually append a new node, you need to allocate that node first:

p = malloc(sizeof(struct node));

Otherwise, you are saying, 'Add a node that does not exist', which is the same as not adding a node in the first place.

Is the int argument of the append() function supposed to be the number of nodes added, or the location to add the node to? EIther one presents possible problems. If it is a number of nodes to be appended, then how are you appending more than one node at a time without using varargs? If, on the other hand, it is a location index, how do you handle the case where there are fewer nodes in the list than the index value?

Could you post the code for your append() and count() functions, please? That way we could tell you if there are any problems with them.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.