Need help with Pointers

J

jstevanus

I am getting an error from my Print() function. It has something to do
with the way I'm trying to output the data from my pointer. Any help
would be greatly appreciated. Here is the code:


void SortedType::print()
{
ofstream outFile;
outFile.open("out.data");

currentPos = listData;

if(listData != NULL) // ADDED LOOP
{
while(currentPos != NULL)
{
outFile << currentPos->info << " ";
currentPos = currentPos->next;
}
}
else
{
outFile << "Linked list is empty, No delete!";
}
}
 
V

Victor Bazarov

I am getting an error from my Print() function.

What error?
It has something to do
with the way I'm trying to output the data from my pointer.

No joke. What's the data you're trying to output?
Any help
would be greatly appreciated. Here is the code:


void SortedType::print()
{
ofstream outFile;
outFile.open("out.data");

currentPos = listData;

What's "currentPos"? What's "listData"?
if(listData != NULL) // ADDED LOOP
{
while(currentPos != NULL)
{
outFile << currentPos->info << " ";

What's "info"?
currentPos = currentPos->next;
}
}
else
{
outFile << "Linked list is empty, No delete!";
}
}

How do you really expect us to help you without seeing how 'SortedType'
is defined?

V
 
K

Karl Heinz Buchegger

Victor said:
How do you really expect us to help you without seeing how 'SortedType'
is defined?

To the OP:
Besides to what Victor has told you:
What you posted looks like a typical way to output
a linked list. If something like that fails, the problem
is often not the output code, but the code that built
the linked list.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Help with pointers 1
Need help with this script 4
Need help with this code 2
Help with code 0
Help with Loop 0
Need Help with Repository Program (Beginner) 1
Help with code plsss 0
Search Results with Pagination 1

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,661
Latest member
sxarexu

Latest Threads

Top