Reputation: 11
I have a linked list where I want to print every element except the last one.
while (node != NULL)
{
printf(" (%d,%d) ", node->x, node->y);
node = node->next;
}
This is the loop im using to print the whole thing, but I can't figure out how to make it exclude the last element. I tried replacing 'node != NULL' with 'node->next != NULL' but it didn't work. Any ideas would be greatly appreciated, cheers
Upvotes: 0
Views: 433
Reputation: 1591
while (node != NULL)
{
if (node->next != NULL)
{
printf(" (%d,%d) ", node->x, node->y);
node = node->next;
}
}
Upvotes: 1