# include
#include
Enum BOOL {False, True};
# define Max 10
Typedef struct dnode/* define two-way chain table structure */
{int number;/* goods number */
Char name (Max);/* goods name */
Int counter; Quantity of the goods/* */
The prior struct dnode * and * next;/* define two Pointers, respectively to the precursor and the subsequent */
} dnode, * dpointer;
Void Initdnode (dpointer & amp;);
BOOL increasednode (dpointer & amp; , int);
BOOL Findkeyworddnode (dpointer & amp; , char *, int);
BOOL Findorderdnode (dpointer & amp; , int);
BOOL Deletednode (dpointer & amp; , int);
Void DnodePrint (dpointer);
Int main () {
Dpointer d;
BOOL temp.
Int num, loc, flag=1;
Char j * ch;
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- program explanation -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Printf (" this program for the warehouse storage system, \ n ");
Printf (" can be achieved according to the order and the goods name lookup warehouse storage, can also add or remove goods, \ n ");
//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Initdnode (d);
DnodePrint (d);
While (flag) {
Printf (" please select: \ n ");
Printf (" \ n 1. Show all the goods information);
Printf (" \ n 2. Add new goods ");
Printf (" 3. Under the name lookup warehouse storage of goods \ n ");
Printf (" 4. Query the warehouse storage situation in sequence \ n ");
Printf (" \ n 5. Remove the existing goods ");
Printf (" 6. Quit \ n ");
The scanf (" % c ", & amp; j);
The switch (j) {
Case '1' : DnodePrint (d);
break;
Case '2' : {
Printf (" please enter the number of types of cargo, \ n ");
Printf (" example: 6 \ n ");
The scanf (" % d ", & amp; Loc);
Temp=increasednode (d (loc);
If (temp==False)
Printf (" resettlement failed! \n");
The else printf (" is successful! \n");
DnodePrint (d);
break;
}
Case '3' : if (d - & gt; Next=NULL)
Printf (" the warehouse is empty! \n");
The else {
Printf (" please enter the name of the goods to query: \ n ");
The scanf (" % c ", & amp; Ch);
Temp=Findkeyworddnode (d, ch, loc);
If (temp==False)
Printf (" could not find information about the goods! \n");
The else printf (" the goods information as follows: % d \ n ", loc);
}
break;
Case '4' : if (d - & gt; Next=NULL)
Printf (" the warehouse is empty! \n");
The else {
Printf (" please enter code: have to query the goods ");
The scanf (" % d ", & amp; Loc);
Temp=Findorderdnode (d (loc);
If (temp==False)
Printf (" could not find information about the goods! \n");
The else printf (" the goods information as follows: % d \ n ", loc, ch);
}
break;
Case '5' : printf (" please enter code: to remove the goods ");
The scanf (" % d ", & amp; Loc);
Temp=Deletednode (d (loc);
If (temp==False)
Printf (" delete failed! \n");
The else printf (" successfully removed a cargo: % c \ n ", ch);
DnodePrint (d);
break;
Default: flag=0;
Printf (" the end of the program, press any key to end! \n");
}
}
Getchar ();
return 0;
}
Void Initdnode (dpointer & amp; D) {
D=(dpointer) malloc (sizeof (dnode));
D - & gt; The prior=NULL;
D - & gt; Next=NULL;
}
BOOL increasednode (dpointer & amp; D, int n) {
int i;
For (I=n; I> 0; - I) {
Dpointer t;
T=(dpointer) malloc (sizeof (dnode));
if(! T)
{return False; }
The else {
T - & gt; Next=d - & gt; Next;
T - & gt; The prior=d;
D - & gt; Next=t;
Printf (" please enter the number of goods, goods name and quantity of the goods \ n ");
Printf (" 3 wang, for example, 10 \ n ");
The scanf (" % d % d % s ", & amp; T - & gt; Number, t - & gt; The name, & amp; T - & gt; Counter);
Return True; }
}
}
BOOL Findkeyworddnode (dpointer & amp; M, char * e, int p) {
While ((m - & gt; The name!=e) | | (m==NULL))
M=m - & gt; Next;
If (m - & gt; The name! E)={
Printf (" no corresponding to find the goods! Please input again! \n");
Return False;
}
The else {
P=m - & gt; Number;
Printf (" has found corresponding goods! \n");
Return True;
}
}
BOOL Findorderdnode (dpointer & amp; M, int e) {
While ((e!=m - & gt; Number) & amp; & (m - & gt; Number<=e))
M=m - & gt; Next;
If (m - & gt; Number! E)={
Printf (" no corresponding to find the goods! Please input again! \n");
Return False; }
The else {
Printf (" has found corresponding goods! \n");
Return True;
}
}
BOOL Deletednode (dpointer & amp; M, int n) {
Dnode d;
While ((n!=m - & gt; Number) & amp; & (m - & gt; Number<=n))
M=m - & gt; Next;
If (m - & gt; Number!=n) {
Printf (" no corresponding to find the goods! Please input again! \n");
Return False; }
The else {
Printf (" has found corresponding goods! \n");
Return True;
}
D.p rior - & gt; Next=d.n ext.
D.n ext - & gt; The prior=d.p rior;
}
Void DnodePrint dpointer (m) {
Dpointer q;
Q=m - & gt; Next;
Printf (" all the goods in the warehouse: ");
While (q!=NULL) {
Printf (" d ", "% c", "d", q - & gt; Number, q - & gt; The name of the q - & gt; Counter);
Q=q - & gt; Next;
}
Printf (" \ n ");
}
CodePudding user response:
His step through bai, you carefully look at the past,Such as the case '3' : if (d - & gt; Next=NULL) this kind of low-level mistakes (a=)
Code function at the end of the day is not others to help you see or interpretation or comment; But by myself calm down and take a long enough time and energy to do it yourself step or set a breakpoint or step to perform to a certain intermediate result shows or written to the log file analysis step by step,
Remind: cow x teacher cannot replace the student understand and use the toilet!
Single step debugging and set breakpoint debugging (VS IDE compilation connection through later, press F10 or F11 key step, press Shift + F11 exit the current function; In a press F9 set breakpoints after press F5 execution stops at the breakpoint,) is one of the programmers must master the skills,
CodePudding user response:
His order with the Debug step F10 debugged, step see if right ~ values of each variable