Struct, Pointer, Linked List

Hi guys, I"m trying to write a program that allow a user to track their DVDs. Use an input file which include these attribute for each movies.

Basically, the user should be able to enter in the name of input file.
Using a structs and pointers, created a linked list of the movies in the input file.
Next, output the linked list to an output file.
Format the output of the plot such that it will word wrap.

The output suppose to look like this
***************************************************************************
MOVIE #: 1 Title: Antwone Fisher
---------------------------------------------------------------------------
Year: 2002 Rating: 7
---------------------------------------------------------------------------
Leading Actor: Denzel Washington Genre 1: Biography
Supporting Actor: Derek Luke Genre 2: Drama
---------------------------------------------------------------------------
PLOT:
Antwone Fisher, a young navy man, is forced to see a psychiatrist after a
violent outburst against a fellow crewman. During the course of treatment
a painful past is revealed and a new hope begins.
***************************************************************************
***************************************************************************
MOVIE #: 2 Title: Bagger Vance, The Legend of
---------------------------------------------------------------------------
Year: 2000 Rating: 6
---------------------------------------------------------------------------
Leading Actor: Will Smith Genre 1: Drama
Supporting Actor: Matt Damon Genre 2: Drama
---------------------------------------------------------------------------
PLOT:
A down-and-out golfer attempts to recover his game and his life with help
from a mystical caddy
***************************************************************************

So far, the problem is my output and I can't display the output. I try to debug it and it turn out that I'm stuck on the while loop.

Here's my output function

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
void OutputList(MovieDVD *head, string outputFileName)
{
	ofstream OFile;
	OFile.open("OFile.txt");

	MovieDVD *dvdPtr;
	dvdPtr = head;

	int counter = 0;

	cout << "Before While Output " << endl;

	while(OFile && (dvdPtr != NULL))
	{
		OFile << left;
		OFile << dvdPtr -> title;
		OFile << setfill('*') << setw(25) << '*' << endl;
		OFile << dvdPtr -> leadActor;
		OFile << setfill('*') << setw(25) << '*' << endl;
		OFile << dvdPtr -> supportActor;
		OFile << setfill('*') << setw(25) << '*' << endl;
		OFile << dvdPtr -> genre;
		OFile << setfill('*') << setw(25) << '*' << endl;
		OFile << dvdPtr -> altGenre;
		OFile << setfill('*') << setw(25) << '*' << endl;
		OFile << dvdPtr -> year;
		OFile << setfill('*') << setw(25) << '*' << endl;
		OFile << dvdPtr -> rating;
		OFile << setfill('*') << setw(25) << '*' << endl;
		OFile << dvdPtr -> synopsis;
		OFile << setfill('*') << setw(25) << '*' << endl;

		dvdPtr = dvdPtr -> next;

		cout << "READ - AFTER LINE OUTPUT" << counter++ << endl;
	}
	cout << " DEBUG -- AFTER WHILE OUTPUT" << endl;
	OFile.close();
}


Here my main function:
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
//INPUT OUTPUT FILE DECLARATION
	ifstream inFile;					//INPUT FILE declaration
	ofstream OFile;						//OUTPUT FILE declaration

	//VARIABLE DECLARATION
	string inputFileName;				//IN  - Input file name
	string outputFileName;				//OUT - Output file name
	string synopsis;
	MovieDVD *head;
	MovieDVD theMovie;

	head = NULL;

	//INPUT
	cout << "What input file would you like to use?: ";
	getline(cin, inputFileName);
	cout << "DEBUG -- BEFORE CREATELIST "<< endl;

	CreateList(head, inputFileName);
	cout << "DEBUG -- AFTER CREAETLIST " << endl;

	//OUTPUT LIST
	cout << "What output file would you like to use?: ";
	getline(cin, outputFileName);


	OutputList(head, outputFileName);
	WordWrap(OFile, head, synopsis);


I add the cout for my debug on output list and only
cout << "Before While Output " << endl and cout << " DEBUG -- AFTER WHILE OUTPUT" << endl come out and skip the while loop. Help me please.
while(OFile && (dvdPtr != NULL))

If you use the debugger (hopefully built in to your IDE), find out the values of the variables OFile and dvdPtr, just before the loop. That should give your answer straight up.

If you are not comfortable using the debugger, then do couts to see what the values of variables are.

BTW, when opening files, check that it worked, not just assume it does.

HTH

Edit: It is one thing to print "Made it to here as a form of checking", but you would be better to print the actual values of the pertinent variables.
Last edited on
I already tried that.
I actually do while (dvdPtr != NULL)

The issue is I can't get through the while loop. I find that out when I was debugging it.
What you think?

How would I able to output the list? Any ideas?

Thanks.
Last edited on
I already tried that.


Ok, what did the debugger report the value of the pointer as being?

I find that out when I was debugging it.


Are you really using the debugger, or do you have a misconception of what debugging is?

If you are using an IDE, hopefully a there is debugging software built in.

You can do breakpoints, have a watchlist of variable values, step through code 1 line at a time - see how values change. That is what I mean by debugger.

Edit:

When you have a pointer, you can also access the members that it points to - this will help to show the pointer is valid.
Last edited on
Topic archived. No new replies allowed.