结构连表 总是出错!!help 在线等待!!
结构体
struct Student
{
int number;
int score;
Student * next;
};
定义全局头指针
Student * head;
下面程序总是出错
void CStruct_ListDlg::OnButton3()
{
Student * kk;
kk=new Student;
kk->number=11;
kk->score=22;
head=kk;
if (head==NULL) AfxMessageBox("head is NULL");
else
{
AfxMessageBox("head is not null");
CStdioFile fTarget;
CString str;
str="c:\11111tshow.txt";
if (!fTarget.Open(str,CFile::modeCreate|CFile::modeWrite))
// if (!fTarget.Open(str,CFile::modeWrite))
{
AfxMessageBox("create Target file fial!");
}
while(!head==NULL)
{
CString str1;
CString str2;
str1.Format("%d",head->number);
str2.Format("%d",head->score);
// str1="2" ;str2="c";
AfxMessageBox(str1);
AfxMessageBox(str2);
fTarget.WriteString(str1+"00"+str2+'\n');
head=head->next;//有问题吗????
}
fTarget.Close();
}
}