Home > Back-end >  V C program malloc memory allocated why not visit?
V C program malloc memory allocated why not visit?

Time:10-17

The code below
RFS * readConfFile () {
The Node * utSocket=initList ();
UtSocket - & gt; Length++;
The Node * utIndex=initList ();
Printf (" length is % d ", utSocket - & gt; Length);
Allocate memory place in initList () function:
Node * initList () {
Node * top=(*) malloc (sizeof (Node));
Node * end=(*) malloc (sizeof (Node));
End - & gt; Data=https://bbs.csdn.net/topics/NULL;
End - & gt; Next=NULL;
End - & gt; Length=0;
Top - & gt; Data=https://bbs.csdn.net/topics/NULL;
Top - & gt; Length=0;
Top - & gt; Next=end;
Printf (" top is % d, the end is % d, top. The length is % d \ n ", top, top - & gt; Next, top - & gt; Length);
Return the top;
}
The wrong place in utSocket - & gt; Length++;


CodePudding user response:


This step when memory has been allocated to the top and assignment,

But is wrong, how to return a responsibility, how to solve?

CodePudding user response:

But from this information, don't see any problems in (to the top after malloc should determine whether the application is successful) suggested that provide more code ~

CodePudding user response:

Top - & gt; data=https://bbs.csdn.net/topics/NULL; What is the wavy lines below tips? Looks like data type int, it is best to initialize a top -> data=0; such

CodePudding user response:

Problem has been solved, in fact, because the file header file does not define initList function, vs compile nor error runs out of the question!
  • Related