dreamuser 0 Newbie Poster

I get a "Debug Assertion Failed" when I go to run my program. More specifically it says "Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)". I assume this is because I'm using pointers incorrectly.

Here is some information about the assignment:

A file contains text representing a prioritized collection of messages. The messages were received one character at a time. At any time during the receipt of a message, a message might have been interrupted by the beginning of a new message of higher priority. (The interrupting message might have been further interrupted by the beginning of a still higher priority message, and so on.) The beginning of a message is always indicated by the '' character. End-lines might occur at any point in the file, but are not part of any message. Your program must read this file (whose name is input from the keyboard). As each message is completed, the program must display it. If any incomplete messages remain when the file has been completely processed, the program must display each with the label "Incomplete: ".
Error processing:
When a character other than end-of-line or '[' is encountered, but no message is being processed, the program must display an error message containing the offending character and identifying the problem. The program should then continue its processing.
Example:
Suppose the file contains the following text:
[abc[PQ[S[123]]T]
defgh]$[AB[uvwxy[1[45]2]CDEF]

The following output should result:
123
S
PQT
abcdefgh
The character '$' does not appear to be part of any message.
45
12
uvwxyCDEF
Incomplete: AB

Here is the required part I am having problems with:

In the main function, use a string-pointer (* String) to represent the current message. Ensure that this pointer is set to NULL before beginning to process the file. (This indicates that there is no current message being processed.) Immediately after completing each message, deallocate the memory referenced by the pointer and then set the pointer back to NULL to show that there is no current message being processed.

and here is my code:

#include <iostream>
#include <fstream>
#include <string>
#include "Stack.h"
using namespace std;

void main ( )
{
	const string MessageFileName = "Dummy.txt";

	ifstream MessageFile;
	char Symbol;
	char SymbolTemp;
	string * CurrentMessage;
	Stack<char> MyStack;

	//Set CurrentMessage to NULL
	CurrentMessage = NULL;

	//Open input file
	MessageFile.open(MessageFileName.c_str());

	//Loop through message file
	while (MessageFile.get(Symbol))
	{
		if (Symbol == '[')
		{
			if (CurrentMessage != NULL)
			{
				MyStack.Push(Symbol); 
				delete CurrentMessage;
			} //end if
			CurrentMessage = new string;
		}
		else if (Symbol == ']')
		{
			if (CurrentMessage != NULL)
			{ 
				cout << CurrentMessage;
				if (MyStack.IsEmpty())
				{ 
					CurrentMessage = NULL; 
				}
				else 
				{ 
					MyStack.Pop(SymbolTemp);
					CurrentMessage = CurrentMessage + SymbolTemp;
				} //end if
			}
			else
			{
				//report an error
			} //end if
		}
		else if (Symbol == '\n')
		{ } //do nothing
		else
		{
			if (CurrentMessage != NULL)
			{
				CurrentMessage = CurrentMessage + Symbol;
			}
			else
			{
				//report an error
			} //end if
		} //end if

	} //end while

	if (CurrentMessage != NULL)
	{
		cout << CurrentMessage;
		delete CurrentMessage;
		CurrentMessage = NULL;
	} //end if

	while (!MyStack.IsEmpty())
	{
		CurrentMessage = new string;
		MyStack.Pop(SymbolTemp);
		CurrentMessage = CurrentMessage + SymbolTemp;
		cout << CurrentMessage;
	} //end while

}

If anyone could help me out with this I would appreciate it. I assume my problem is I'm using the pointer CurrentMessage incorrectly throughout my main program.