Home > Back-end >  The malloc memory application is successful but cannot access problems
The malloc memory application is successful but cannot access problems

Time:12-16

 # pragma once 
#include
using namespace std;
#include
#include
#include
#include
#include



# define LENTH sizeof (struct the teacher)



//fuction
Void SpringTeacherInformation (struct the teacher * p);
Struct the teacher * Creat ();

//value
Int Order * Order (string);
The string order;
Int LenthOfList=0;

Struct student
{
string name;
Float score;
};
Struct the teacher
{
string name;
Struct student stu [4].
Struct the teacher * next;
};

this is my headers
 # include "head h" 

Int main ()
{
Cout & lt; Cout & lt; <"Welcome to entry system!" While (1)
{
Cout & lt; <"If the input data?" ;
If (Order (& amp; The order)==1)
{
Creat ();
};
}
Cout & lt; <"End of the system... "& lt; system("pause");

return 0;

}

 
The teacher * Creat ()
{
The static head; the teacher *
The static the teacher * p1=nullptr;
The static the teacher * p2=nullptr;

P1=(struct) the teacher * malloc (LENTH);
P1 p2=;
int i;

//create the first data chain table
If (p1==nullptr)
{
Cout & lt; <"Create data failed, please try again later... "& lt; Return nullptr.
}
The else
{
Cout & lt; The head=nullptr;
Cout & lt; <"Please input the teacher's name:";
Scanf_s (" % s ", & amp; (p1 - & gt; Name));

The last line "scanf_s... The abnormal
""0 x7a9de63c (ucrtbased. DLL) (located in the dome. Exe) caused by abnormal: 0 xc0000005: when writing position 0 x01252000 access conflict,
"

My own practice bracelet:
I speculated that abnormal failure reason is mallco application memory or have no access to memory, but memory should apply validation is successful,,,
Really what's the reason, I didn't learn c + + is a small white, Daniel answer ~ ~ ~

CodePudding user response:

C + +, use the new application memory, the other p1 - & gt; When the name is a string, the scanf don't need & amp; The symbols
Cout & lt;
  • Related