Home > Back-end >  Problems pointer in C
Problems pointer in C

Time:10-05

Don't know which there is something wrong with this code, compile time to stu0 - & gt; Next that can go wrong, say the access violation, beg you explain, thank you,
Student for a structure, and pointer and seven data,
Void List: : readfile ()
{
CStdioFile file1.
Cstrings m_File_Path="studentinfo. TXT";
File1. Open (m_File_Path CFile: : modeReadWrite);
Cstrings filedata;
Student * stu0=head;
Student stu2;
Student stu1 *;
While (file1. ReadString (filedata))//read the contents of the file,
{
Char split [4]="";
Cstrings STR=filedata;
Int nindex1=STR. Find (split);
If (nindex1 & gt;=0)
{
Stu2. Name=STR. Left (nindex1);
STR=STR. Right (STR) GetLength () - nindex1-3);
}
Int nindex2=STR. Find (split);
If (nindex2 & gt;=0)
{
Stu2. Sex=STR. Left (nindex2);
STR=STR. Right (STR) GetLength () - nindex2-3);
}
Int nindex3=STR. Find (split);
If (nindex3 & gt;=0)
{
Stu2. Stunum=STR. Left (nindex3);
STR=STR. Right (STR) GetLength () - nindex3-3);
}
Int nindex4=STR. Find (split);
If (nindex4 & gt;=0)
{
Stu2. Classes=STR. Left (nindex4);
STR=STR. Right (STR) GetLength () - nindex4-3);
}
Int nindex5=STR. Find (split);
If (nindex5 & gt;=0)
{
Stu2. Academy=STR. Left (nindex5);
STR=STR. Right (STR) GetLength () - nindex5-3);
}
Int nindex6=STR. Find (split);
If (nindex6 & gt;=0)
{
Stu2. Phonenum=STR. Left (nindex6);
STR=STR. Right (STR) GetLength () - nindex6-3);
}
Int nindex7=STR. Find (split);
If (nindex7 & gt;=0)
{
Stu2. Roomnum=STR. Left (nindex7);
STR=STR. Right (STR) GetLength () - nindex7-3);
}
Stu2. Next=NULL;
Stu1=new student (stu2);
If (head==NULL)
The head=stu1;
The else
Stu0 - & gt; Next=stu1;
}
}

CodePudding user response:

Student * stu0=head; Your stu0 might be a null pointer

CodePudding user response:

But not the head is assigned to a stu0? Is not as long as the head have value, she would have a value?

CodePudding user response:

The head may be null Pointers,

refer to the second floor shu_mo response:
but not gave stu0 head fu? Is not as long as the head have value, she would have a value?

CodePudding user response:

The head==NULL
  • Related