Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have c++ code for computing multilayer perceptron character recognition classifier i read feature vectors from txt file but when executing i have this error
Unhandled exception at 0x008420fa in mlp.exe: 0xC0000005: Access violation writing location 0x0000007f.

where is the error
this is the code:

void MLP::loaddata(){

	
	 

	 const char *trn_file="Winners.trn";
	const char *tst_file="Winners.tst";

	ifstream Trn(trn_file);
	ifstream Tst(tst_file);
	for(int i= 0;i<NumTrn;i++)
	{
		Trn>>TrainLabels[i];
		for(int j=0;j<NumFe;j++)
			Trn>>TrainData[i][j];
	}
	for(int i= 0;i<NumTst;i++)
	{
		Tst>>TestLabels[i];
		for(int j=0;j<NumFe;j++)
			Tst>>TestData[i][j];
	}

C#
for (int i= 0; i<NumTrn; i++){

      for (int j= 0;j<NumFe;j++)
      //input
      cvSetReal2D(&TrnData, i, j, TrainData[i][j]);
      //Output
      cvSet1D(&TrnLabels, i, cvScalar(TrainData[i][NumFe]));
    }

    //for test matrix
    for (int i=0; i<NumTst; i++){

      for (int j=0;j<NumFe;j++)
      //input
      cvSetReal2D(&TstData, i, j, TestData[i][j]);
      //Output
      cvSet1D(&TstLabels, i, cvScalar(TestData[i][NumFe]));
    }
     // CALCMLP( TrnData,  TrnLabels, TstData, TstLabels);
}


any advise
thanks
Posted
Comments
KarstenK 2-Dec-14 8:10am    
have you used your debugger?
MSMHMA 2-Dec-14 8:20am    
yes i used it
barneyman 2-Dec-14 22:29pm    
and what line did it crash on?

you're crashing while trying to write byte 128 from NULL - some string/array you're allocating is failing, or an address you're getting from somewhere is NULL

use the debugger to find the line that's crashing, that should identify which ptr is broken, then add check code along the way to find out when it get's NULL'd
MSMHMA 5-Dec-14 14:01pm    
i checked it and find that the TrainLabels, TrainData,TestLabels and TestData have no data but i don't know why they can't read data from winners files where is the problem
any advise
barneyman 5-Dec-14 18:55pm    
my advice would be to try some basic debugging! Is the file there, does the ifstream open succeed, is there data in the file, >> reads until whitespace, is there too much whitespace?

and, on a practical point, i'd advise against using flat files to store data if you can - xml/json is much more defensive

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900