Home > Software engineering >  Memory to run the program, can't read, what reason be?
Memory to run the program, can't read, what reason be?

Time:09-22

I'm just a program yourself reappeared the teacher in class, the novice completely don't know where is the problem?? I hope someone can answer, thank you!
 
//CMyView message handlers

Void CMyView: : OnSelchangeId ()
{
//TODO: Add your the control notification handler code here
CMyDoc * pDoc=GetDocument ();
M_nCurrentNo=m_xuehao. GetCurSel ();
M_name=pDoc - & gt; M_student [m_nCurrentNo]. Name;
M_age=pDoc - & gt; M_student [m_nCurrentNo]. Age;
M_jieshao=pDoc - & gt; M_student [m_nCurrentNo]. School;
M_sex=pDoc - & gt; M_student [m_nCurrentNo] sex;
M_number=pDoc - & gt; M_student [m_nCurrentNo]. Tel;
The UpdateData (false);
}

Void CMyView: : OnChangeAge ()
{
CMyDoc * pDoc=GetDocument ();
The UpdateData (true);
If (pDoc - & gt; M_student [m_nCurrentNo]. Age!=m_age)
{
PDoc - & gt; M_student [m_nCurrentNo]. Age=m_age;
PDoc - & gt; SetModifiedFlag ();
}

}

Void CMyView: : OnChangeJieshao ()
{
CMyDoc * pDoc=GetDocument ();
The UpdateData (true);
If (STRCMP (pDoc - & gt; M_student [m_nCurrentNo] school, m_jieshao))
{
Strcpy (pDoc - & gt; M_student [m_nCurrentNo] school, m_jieshao);
PDoc - & gt; SetModifiedFlag ();
}


}

Void CMyView: : OnChangeName ()
{
CMyDoc * pDoc=GetDocument ();//access pointer to the document class object
The UpdateData (true);//use the control values to update variables associated with the
If (STRCMP (pDoc - & gt; M_student [m_nCurrentNo]. Name, m_name))
{
Strcpy (pDoc - & gt; M_student [m_nCurrentNo]. Name, m_name);
PDoc - & gt; SetModifiedFlag ();//set the data change sign
}


}

Void CMyView: : OnChangeNumber ()
{
CMyDoc * pDoc=GetDocument ();
The UpdateData (true);
If (STRCMP (pDoc - & gt; M_student [m_nCurrentNo]. Tel, m_number))
{
Strcpy (pDoc - & gt; M_student [m_nCurrentNo]. Tel, m_number);
PDoc - & gt; SetModifiedFlag ();
}


}

Void CMyView: : OnChangeSex ()
{
CMyDoc * pDoc=GetDocument ();
The UpdateData (true);
If (STRCMP (pDoc - & gt; M_student [m_nCurrentNo] sex, m_sex))
{
Strcpy (pDoc - & gt; M_student [m_nCurrentNo] sex, m_sex);
PDoc - & gt; SetModifiedFlag ();
}

}

Void CMyView: : OnOpenfile ()
{
//TODO: Add your command handler code here
Cstrings strFilter="Dat Files (*. Dat) | *. Dat | All Files (*. *) | *. * | |";
//1) start the general file dialog box, select the file name
CFileDialog FileDlg (true, NULL, NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT (LPCSTR) strFilter, this);
If (FileDlg. DoModal ()!=IDOK) return;
Cstrings strFileName=FileDlg. GetPathName ();
//(2) open the file
CFile f;
if(! F.O pen (strFileName CFile: : modeRead))
{
AfxMessageBox (" failed to open the file ");
return;
}
//(3) to read data in a file stored in the document class data members
CMyDoc * pDoc=GetDocument ();
F.R ead (& amp; M_nCurrentNo, sizeof (int));
for(int i=0; i<40; I++)
{
F.R ead (pDoc - & gt; M_student [I]. Name, 10);
F.R ead (pDoc - & gt; M_student [I]. Sex, 3);
F.R ead (& amp; (pDoc - & gt; M_student [I]. Age), sizeof (int));
F.R ead (pDoc - & gt; M_student [I]. Tel, 14);
F.R ead (pDoc - & gt; M_student [I]. School, 50);
}
F. lose ();
//(4) the document data is passed to the view class data members, and displays a
M_xuehao. SetCurSel (m_nCurrentNo);
M_name=pDoc - & gt; M_student [m_nCurrentNo]. Name;
M_age=pDoc - & gt; M_student [m_nCurrentNo]. Age;
M_jieshao=pDoc - & gt; M_student [m_nCurrentNo]. School;
M_sex=pDoc - & gt; M_student [m_nCurrentNo] sex;
M_number=pDoc - & gt; M_student [m_nCurrentNo]. Tel;
The UpdateData (false);

}

Void CMyView: : OnSavefile ()
{
//TODO: Add your command handler code here
Cstrings strFilter="Dat Files (*. Dat) | *. Dat | All Files (*. *) | *. * | |";
CFileDialog FileDlg, false, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, (LPCSTR) strFilter, this);
If (FileDlg. DoModal ()!=IDOK)
return;//1) start the general file dialog
Cstrings strFileName=FileDlg. GetPathName ();
CFile f;//(2) open the file
F.O pen (strFileName CFile: : modeCreate | CFile: : modeWrite);
CMyDoc * pDoc=GetDocument ();//(3) to write files stored data
F.W rite (& amp; M_nCurrentNo, sizeof (int));
for(int i=0; i<40; I++) {
F.W rite (pDoc - & gt; M_student [I]. Name, 10);
F.W rite (pDoc - & gt; M_student [I]. Sex, 3);
F.W rite (& amp; (pDoc - & gt; M_student [I]. Age), sizeof (int));
F.W rite (pDoc - & gt; M_student [I]. Tel, 14);
F.W rite (pDoc - & gt; M_student [I]. School, 50);
}
F. lose ();//(4) close the file
}

CodePudding user response:

Step through a "unhandled exception in * * *. Exe (MSVCRTD. DLL) : 0 xc0000005: Access Violation"
According to determine a "both please enter the path for STRCMP. Asm"

CodePudding user response:

STRCMP calls, parameter has a problem, have a look at

CodePudding user response:

C + + general program need to pay attention to the array bounds checking
The program of pDoc - & gt; Check m_student access, no boundaries, can easily access seams

Tip can not access, the debug menu to open the call stack, step by step to see your code calls, double click, you will see lines of code with the question

CodePudding user response:

You are directly using m_nCurrentNo program,, there is no judgment whether the values for invalid values, you use a did not determine whether effective value as an array subscript, it is very easy to a problemnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related