Hi there. I'm back :-)
Code:
void GetNth (node** head)
{
node* current = *head;
node* walker = *head;
int n, length, count;
printf("Input n ... ");
scanf("%d",n);
length = 0;
count = 0;
if (current == NULL)
{
length = 0;
}
else
{
while (current != NULL)
{
length++;
current = current->next;
}
}
if (n>length)
{
printf("\nNo such Node\n");
}
else
{
do
{
walker = walker->next;
count++;
} while (count != n);
/* found the Nth*/
printf("N-th => NAME: %s\tAGE: %d\n",walker->name,walker->age);
}
}
}
this doesn't work no matter which number I enter for n, and no matter how long the list is. can you help me?