Whats wrong with this linked list?

Any time values get entered into the list nothing happens nor have they been added. Here's a sample of what I've done but I'm getting a little confused whats wrong with it.

main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
int main()
{

	// The beginning node in the linked list.
	Node *pFirstNode = NULL;

	//Used to move along the linked list
	Node *pCurrentNode = pFirstNode;

	int option = 0;
	
	do
	{
		DisplayLinkedList( pFirstNode, pCurrentNode );

		printf( "\nPlease select an option : " );
		printf(	"\n0. Exit the program." );
		printf(	"\n1. Add a node to the end of the list.");
		printf(	"\n2. Delete the start node from the list.");
		printf(	"\n3. Delete the end node from the list.");
		printf(	"\n4. Move the current pointer on one node.");
		printf(	"\n5. Move the current pointer back one node.\n\n  >> ");
		scanf_s( "%d", &option );

		switch (option)
		{
			case 1 : 
				AddNode( pFirstNode, pCurrentNode );
				break;

			case 2 : 
				DeleteStartNode( pFirstNode );
				break;

			case 3 : 
				DeleteEndNode( pFirstNode );
				break;

			case 4 : 
				MoveCurrentNodeForward( pCurrentNode );
				break;

			case 5 : 
				MoveCurrentNodeBack( pFirstNode, pCurrentNode );
				
		}
	}while( option != 0 );

	return 0;
}


Linked List Functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
void AddNode( Node *pStart, Node *pCurrent )
{
	// Temporary pointers
	Node *pTemp, *pTempTwo;

	// Reserve space for new node and fill it with data
	pTemp = new Node;
	
	// User data entry for a new node
	printf( "Please enter the age of the person : " );
	scanf_s( "%d", &pTemp->age );
	printf( "Please enter the height of the person : " );
	scanf_s( "%f", &pTemp->height);

	pTemp->next = NULL;

	// Set up link to this node
	if( pStart == NULL )
	{ 
		pStart = pTemp;
		pCurrent = pStart;
	}
	else
	{ 
		pTempTwo = pStart;

		// We know this is not NULL - list not empty!
		while ( pTempTwo->next != NULL )
		{  
			pTempTwo = pTempTwo->next;
			// Move to next link in chain
		}
		pTempTwo->next = pTemp;
	}
}
I believe you were intending that AddNode() modify pStart and/or pCurrent and actually have main's version of pFirstNode and pCurrentNode be changed by AddNode(), but that is not the case.

Make AddNode take its two pointer parameters by reference.
I know how to take it by reference but is it possible to do it at all by taking it by pointers?
Pointer to pointer is the alternative.
Could you explain exactly what you mean to that? As thats what I thought I was basically doing.

Thanks jsmith.
AddNode would need to be declared like this:

 
void AddNode( Node **pStart, Node **pCurrent )


Yup thats fine, but the inside of the function itself I'm a little confused on how I should be doing it. Because pCurrent = pStart; and **pCurrent = **pStart; both compile for example but I'm not to sure if I should be using one or the other. As the way I have it compiles but it crashes when I user input the age. Debug just tells me age = -87####### so I'm a tad confused :(

Thanks
All good fixed now :)

Thanks.
Topic archived. No new replies allowed.