AdventGamer 0 Newbie Poster

ok well i'm having issues sending a char array to a listbox. To do a little explanation on the code itself... The point of this part is to take a hexidecimal string and convert it to a alphabetical string (this part works and has been tested in a console application). I then have a vShowText function that i used to add items into my listbox. It has worked thus far and i have even added char arrays to the listbox using it. In this particular case i can't seem to make the char array show up into the listbox, it just inserts a line of D like characters. This is sorta difficult to explain so i hope i'm doing a good enough job of it. I will post code to help explain more below.

here is my vShowText function that is being used to insert text into the listbox.

void vShowText(HWND	hChildHandle, char *szText)
{
	int Line;
	
	// add string to the listbox
	SendMessage(hChildHandle,LB_ADDSTRING,0,(LPARAM)szText);
	
	// determine number of items in listbox
	Line = SendMessage(hChildHandle,LB_GETCOUNT,0,0);
	
	// flag last item as the selected item, to scroll listbox down
	SendMessage(hChildHandle,LB_SETCURSEL,Line-1,0);
	
	// unflag all items to eliminate negative highlite
	SendMessage(hChildHandle,LB_SETCURSEL,-1,0);
}

below is where my problem is. This is the actual code to change the hex string into a alphabetical one. When the loop is done going through the hex string, ptrBuffer is reset to point to the first element in the char buffer[100] array. Then vShowText is called to display the …

AdventGamer 0 Newbie Poster
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string answer;

    cout << "This is a question? ";
    cin >> answer;
    
    system("PAUSE");
    return(0);
}
AdventGamer 0 Newbie Poster

well that depends. An array of objects usually refers to a array of class objects. What you are doing and describing is just a typical array of integers etc. A typical array of objects would be declared like something below.

MyClass obj[10];

If by object you just mean normal values then it looks ok to me.

AdventGamer 0 Newbie Poster

thanks it works, guess i was way closer to begin with.

AdventGamer 0 Newbie Poster

ok after some book reading and googling, i came up with some changes that to me look correct but the compiler thinks differently. Can anyone spot a problem? When it runs i'm getting

Unhandled exception at 0x01022646 in Joust06AJBO.exe: 0xC0000005: Access violation writing location 0x00000000.

template <typename T>
node<T> *copyList(node<T> *front)
{
	node<T> *tempHead = front;
	node<T> *newList = NULL;
	node<T> *tail = NULL;

	while (tempHead != NULL)
	{
		if (newList == NULL)
		{
			newList->nodeValue = tempHead->nodeValue;
			newList->next = NULL;
			tail = newList;
		}
		else
		{
			tail = tail->next;
			tail->nodeValue = tempHead->nodeValue;
			tail->next = NULL;
		}
		tempHead = tempHead->next;
	}
	return (newList);
}
AdventGamer 0 Newbie Poster

thank you both for the help, and as for mike's post I can't really do that on this project, but it is nice to see alternatives. And for firstPersons post I'm pretty confused. Below is what I have so far, still working on figuring this out.

template <typename T>
node<T> *copyList(node<T> *front)
{
	//set tempHead to front's nodeValue, not sure if this is correct.
	node<T> *tempHead = new node<T>(front->nodeValue);
	node<T> *temp;
	node<T> *tempHeadCopy;

	//iterate through list and copy to newly allocated memory
	while(front != NULL)
	{

		//create new node and assign it the value of tempHead's nodeValue
		temp = new node<T>(tempHead->nodeValue);
		//set tempHead's next equal to temp
		tempHead->next = temp;
	}

	return tempHeadCopy;
}
AdventGamer 0 Newbie Poster

I've been working with linked list and i'm currently trying to make my copyList template function work. It should return the head of the new list. Could someone give me some advice on how to fix it, currently i get no output when i try to print the copied list.

#include <iostream>
#include <list>
#include "node.h"
#include <string>

using namespace std;

template <typename T>
node<T> *copyList(node<T> *front)
{
	//set tempHead to front's nodeValue, not sure if this is correct.
	node<T> *tempHead = new node<T>(front->nodeValue);
	node<T> *temp;

	//iterate through list and copy to newly allocated memory
	while(front->next != NULL)
	{
		//create new node
		temp = new node<T>;
		//set newnode equal to tempHead's next.
		temp = tempHead->next;
	}

	//should return the head of the new list but i think
	//there is something wrong here.
	node<T> *temp2 = tempHead;
	return temp2;
}

template <typename T>
void writeLinkedList(node<T> *front, const string& separator = " ")
{
	//front points at first node. curr moves through the list
	node<T> *curr;
	curr = front;

	while (curr != NULL)
	{
		//output node value and move to the next node
		cout << curr->nodeValue << separator;
		curr = curr->next;
	}
}

int main()
{
	//create list and add items to front
	node<double> *front = NULL, *p, *newHead = NULL;
	int i = 0, n = 0;

	p = new node<double>(5.5, front);
	front = p;
	p = new node<double>(6.7, front);
	front = p;
	p = new node<double>(15.3, front);
	front = p;
	p = new node<double>(3.14, front);
	front = p;
	p …
AdventGamer 0 Newbie Poster

here's what i have so far.. i think i'm getting close, the program runs but doesn't work and doesn't give me a error, so i'm in the process of trying to figure it out.

#include <iostream>
#include <list>
#include <string>
#include "node.h"

using namespace std;

template <typename T>
void WriteLinkedList(node<T> *front, const string& separator = " ")
{
	//front points at first node. curr moves through the list
	node<T> *curr;
	curr = front;

	while (curr != NULL)
	{
		//output node value and move to the next node
		cout << curr->nodeValue << separator;
		curr = curr->next;
	}
}

template <typename T>
void CompareNodes(node<T> * & front, T& target)
{
	node<T> *curr = front, *prev = NULL;

	while (curr != NULL )
	{
		if (curr->nodeValue < target)
		{
			removeNode(front,curr);
			
		}
	}
}

template <typename T>
void removeNode(node<T> *& front, node<T> *& nodeToRemove)
{
	node<T> *prev = &findNodeBefore(front, nodeToRemove);
	prev->next = nodeToRemove->next;
	delete nodeToRemove;
}

template <typename T>
node<T> findNodeBefore(node<T> *& front, node<T> *& nodeToRemove)
{
	node<T> *temp = front;
	node<T> *prev = NULL;

	do{
		prev = temp;
		temp = temp->next;
	}while(temp->next != nodeToRemove);
	
	//return(0);
	return *prev;
}

int main()
{
	node<int> *front = NULL, *p;
	int i = 0, n = 0;

	int num1 = 0, num2 = 0, num3 = 0, num4 = 0, num5 = 0;

	cout << "Enter 5 numbers to be inserted into the list: " << endl;
	cin >> num1 >> num2 >> num3 >> num4 >> num5;

	p = new node<int>(num1, front);
	front = p; …
AdventGamer 0 Newbie Poster

thanks for the help. I'm pretty new to linked lists though, and I'm not really sure how to go about creating the findNodeBefore function.

AdventGamer 0 Newbie Poster

I'm currently working on a program with linked lists. The program asks you to enter five integers, and every time you enter one that integer is added to the front of the list. My issue is that for each input, i need to insert the node at the beginning of the list (which is working), but then i need to scan the rest of the list and delete all nodes that are less than that node value. I have the CompareNodes function that i'm currently using to do this, however I'm a bit confused and haven't made it work. If you have some advice please let me know.

#include <iostream>
#include <list>
#include <string>
#include "node.h"

using namespace std;

template <typename T>
void WriteLinkedList(node<T> *front, const string& separator = " ")
{
	//front points at first node. curr moves through the list
	node<T> *curr;
	curr = front;

	while (curr != NULL)
	{
		//output node value and move to the next node
		cout << curr->nodeValue << separator;
		curr = curr->next;
	}
}

template <typename T>
void CompareNodes(node<T> * & front, T& target)
{
	node<T> *curr = front, *prev = NULL;

	while (curr != NULL )
	{
		if (curr->nodeValue < target)
		{

			delete curr;
		}
		else
		{
			prev = curr;
			curr = curr->next;
		}
	}
}

int main()
{
	node<int> *front = NULL, *p;
	int i = 0, n = 0;

	int num1 = 0, num2 = 0, num3 = 0, num4 = 0, num5 = 0;

	cout << "Enter 5 …