Hello, I am new to C++ windows programming and have only taken 1 class in c++ in my life (I have experience with other languages and OOP).

I'm using Visual C++ 2008. and my project is created by the wizard for a Windows Forms Application. (I'm guessing this means CLI or whatever that is)

I am trying to make a program that has a small text "database" that reads in to a 2 dimensional [100][2] array. the data reads in and also outputs as it should. Eventually, the program ends (seems like after only 30 'events' on the form). the debugger always give me an exit error when the program freezes.

The program '[2716] Project_1.exe: Managed' has exited with code -805306369 (0xcfffffff).

I have looked everywhere online and cannot find an answer to this.

when I look at the taskmanager during execution, the memory seems to go up in small increments when I have do anything on the form (even just move the mouse). the program always freezes when the memory gets to about 30,000 kb. this seems REALLY small, so I don't think it's a memory leak.


Here's the code for the header file that has pretty much everything but the functions. I'm sorry if this seems long

//beginning of file
int items[100][2];
int pictureData[9][4];

int readFromFile();
int writeToFile();
int setLocation(int idnum, int location);
int getLocation(int idnum);
int readLocData();


#pragma once


namespace Project_1 {
	using namespace std;
	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

.
.
.
.
.
.
//skipped a bunch of lines that Visual Studio automatically created for buttons and stuff 

#pragma endregion

//event handler things
	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
				 readLocData();
				 readFromFile();
			 }
	private: System::Void readButton_Click(System::Object^  sender, System::EventArgs^  e) {
				 //get item location
				 try{
					 if(readBox->Text != "")
						 locBox->Text = getLocation(int::Parse(readBox->Text)).ToString();
					 else
						 System::Windows::Forms::MessageBox::Show( L"Please enter a valid ID", L"Try again",System::Windows::Forms::MessageBoxButtons::OK,System::Windows::Forms::MessageBoxIcon::Warning);
				 }
				 catch(Exception ^ FormatException){
					 System::Windows::Forms::MessageBox::Show( L"Please enter a valid ID (only integers)", L"Try again",System::Windows::Forms::MessageBoxButtons::OK,System::Windows::Forms::MessageBoxIcon::Warning);
				 }
			 }
	private: System::Void writeButton_Click(System::Object^  sender, System::EventArgs^  e) {
				 //write item location or create new item
				 if(readBox->Text != ""&&locBox->Text != ""){
					 if(checkBox1->Checked)
					 {	//create new item allowed
						 try{
							 if(setLocation(int::Parse(readBox->Text),int::Parse(locBox->Text))==-1)
							 {
								 //make a new item if ID does not exist in database
								 for(int i = 0; i < sizeof(items)/sizeof(items[0]); i++)
								 {
									 if(items[i][0]==0)
									 {
										 items[i][0]=int::Parse(readBox->Text);
										 items[i][1]=int::Parse(locBox->Text);
										 //toolStripLabel1->Text = "Wrote ID and Location";
										 break;
									 }
								 }
							 }
						 }
						 catch(Exception ^ FormatException){
							 System::Windows::Forms::MessageBox::Show( L"ID/Location not valid", L"Sorry",System::Windows::Forms::MessageBoxButtons::OK,System::Windows::Forms::MessageBoxIcon::Information);
						 }
					 }
					 else
					 {	//do not create new item, but if possible overwrite old one
						 try{
							 if(setLocation(int::Parse(readBox->Text),int::Parse(locBox->Text))==-1)
							 {
								 System::Windows::Forms::MessageBox::Show( L"Could not find item", L"Sorry",System::Windows::Forms::MessageBoxButtons::OK,System::Windows::Forms::MessageBoxIcon::Information);
							 }
						 }
						 catch(Exception ^ FormatException){
							 System::Windows::Forms::MessageBox::Show( L"ID/Location not valid", L"Sorry",System::Windows::Forms::MessageBoxButtons::OK,System::Windows::Forms::MessageBoxIcon::Information);
						 }
					 }
				 }
				 else
					 System::Windows::Forms::MessageBox::Show( L"Please enter a valid ID/Location", L"Try again",System::Windows::Forms::MessageBoxButtons::OK,System::Windows::Forms::MessageBoxIcon::Warning);
				 writeToFile();
			 }
	private: System::Void deleteButton_Click(System::Object^  sender, System::EventArgs^  e) {
				 //delete item
				 try{
					 int temp = getLocation(int::Parse(readBox->Text));
					 if(temp != -1)
					 {
						 for(int i = 0; i < sizeof(items)/sizeof(items[0]); i++)
						 {
							 if(items[i][0]==int::Parse(readBox->Text))
							 {
								 items[i][0]=0;
								 items[i][1]=0;
								 break;
							 }
						 }
						 writeToFile();
					 }
					 else
						 System::Windows::Forms::MessageBox::Show( L"Item not found", L"Try again",System::Windows::Forms::MessageBoxButtons::OK,System::Windows::Forms::MessageBoxIcon::Warning);
				 }
				 catch(Exception ^ FormatException){
					 System::Windows::Forms::MessageBox::Show( L"Not a valid ID", L"Try again",System::Windows::Forms::MessageBoxButtons::OK,System::Windows::Forms::MessageBoxIcon::Warning);
				 }
			 }
	private: System::Void dispButton_Click(System::Object^  sender, System::EventArgs^  e) {
			 }
};
}

here's the code with my functions

int ::readFromFile()
{
	string line;
	ifstream myfile ("data.dat");
	if (myfile.is_open())
	{
		for(int i = 0; myfile.good(); i++ )
		{
			myfile >> line;
			items[i][0] = atoi(line.c_str());
			myfile >> line;
			items[i][1] = atoi(line.c_str());
		}
		myfile.close();
		//System::Windows::Forms::MessageBox::Show( L"File read correctly", L"Congrats",System::Windows::Forms::MessageBoxButtons::OK);
	}

	else
		System::Windows::Forms::MessageBox::Show( L"Could not open file", L"ERROR",System::Windows::Forms::MessageBoxButtons::OK);

	myfile.close();
	return 0;
}
int ::writeToFile()
{
	ofstream myfile;
	myfile.open ("data.dat");
	if(myfile.is_open())
	{
		for(int i = 0; i < sizeof(items)/sizeof(items[1]); i++)
			myfile << items[i][0] << " " << items[i][1] <<"\n";
		myfile.close();
	}
	else
		System::Windows::Forms::MessageBox::Show( L"Could not open file", L"ERROR",System::Windows::Forms::MessageBoxButtons::OK);

	myfile.close();
	return 0;
	/*
	//gives random numbers to each of the items in the array for creating a random data file
	ofstream myfile;
	myfile.open ("data.dat");
	srand(time(NULL));
	int p;
	for(int i = 0; i <= sizeof(items)/sizeof(items[1]); i++)
	{
	p=rand() % 8 + 1;
	myfile << i << " " << p <<"\n";
	}
	myfile.close();
	return 0;
	*/
}
int ::setLocation(int idnum, int location)
{
	//search through array. if it is found, set location, return 

	for(int i = 0; i < sizeof(items)/sizeof(items[1]); i++)
	{
		if(idnum==items[i][0]) //found id
		{
			items[i][1]=location;
			return items[i][1];
		}
	}
	//could not find
	return -1;
}
int ::getLocation(int idnum)
{
	//search through array. if it is found, return location, otherwise return -1
	for(int i = 0; i < sizeof(items)/sizeof(items[1]); i++)
	{
		if(idnum==items[i][0]) //found id
			return items[i][1];
	}
	return -1;
}
int ::readLocData()
{
	string line;
	ifstream myfile; //("location.dat");
	myfile.open("location.dat");
	if (myfile.is_open())
	{
		for(int i = 0; myfile.good(); i++ )
		{
			myfile >> line;
			pictureData[i][0] = atoi(line.c_str());
			myfile >> line;
			pictureData[i][1] = atoi(line.c_str());
			myfile >> line;
			pictureData[i][2] = atoi(line.c_str());
			myfile >> line;
			pictureData[i][3] = atoi(line.c_str());
		}
		myfile.close();
	}
	else
		System::Windows::Forms::MessageBox::Show( L"Could not open location file", L"ERROR",System::Windows::Forms::MessageBoxButtons::OK);

	myfile.close();
	return 0;
}

If this is similar to anything anyone else has seen, please let me know.
Thanks in advance

Run your code under a debugger (You use Visual Studio after all) to get more detailed information about the crash.

The pasted code is too long to read through when the range can be narrowed down very easily ;)

I managed to find out that it was because /clr:pure was on or something. When i made it just /clr it worked fine.

Also, the debugger doesn't ever seem to give much info when it crashed, only 1 line that showed the exit code/error

Thanks for the help though

This question has already been answered. Start a new discussion instead.