//testc13. CPP: defines the entry point of the console application,
//
# include "stdafx. H"
#include
#include
//NPC structure information
Typedef struct _NPC
{
Char name [20].
Int nx, ny;
Int nid;
NPC};
Typedef struct _NODE
{
NPC * data;
Struct _NODE * pNext;
} the NODE;
NODE * head;//head node
Void invoke the ();
Void queryNode (int nid);
Void printNode ();
Void insertNodeAt (NODE, the NODE * int index);
//enumerated type
Enum SYSMENU
{
ADDNPC=1,//add
QUERY, QUERY//
PRINT,
The QUIT
};
Int main ()
{
Enum SYSMENU input;
The head=NULL;
While (1)
{
//display system main menu
Printf (" \ \ \ n1 nNPC management system to add NPC n2 query NPC \ n3 print all NPC information \ n4 interchange exits system \ n ");
Scanf_s (" % d ", & amp; Input);
//determine which user selects the menu item
The switch (input)
{
Case ADDNPC:
Printf (" \ n you selected 1, add ");
Invoke the ();
break;
In case the QUERY:
Printf (" \ n you selected 2, query ");
break;
Case PRINT:
Printf (" \ n you chose 3, print ");
PrintNode ();
break;
In case the QUIT:
Printf (" \ n you chose 4, exit ");
exit(0);
break;
Default:
break;
}
}
system("pause");
return 0;
}
Void invoke the ()
{
//the new node
NODE * pNewNode=(*) malloc (sizeof (NODE));
PNewNode - & gt; Data=https://bbs.csdn.net/topics/* (NPC) malloc (sizeof (NPC));
PNewNode - & gt; PNext=NULL;
//the node assignment
Printf (" please enter the NPC id name nx ny \ n ");
Scanf_s (" % d % d % d % s ", & amp; PNewNode - & gt; Data - & gt; Nid,
PNewNode - & gt; Data - & gt; The name,
& PNewNode - & gt; Data - & gt; Nx,
& PNewNode - & gt; Data - & gt; Ny);
If (head==NULL)
{
//added directly node
The head=pNewNode;
}
The else
{
//find the last node, add
NODE * pNode;
PNode=head;
While (pNode - & gt; PNext!=NULL)
{
PNode=pNode - & gt; PNext;
}
PNode - & gt; PNext=pNewNode;
}
}
Void queryNode (int nid)
{
}
Void printNode ()
{
NODE * pNode;
PNode=head;
While (pNode - & gt; PNext!=NULL)
{
//print node information
Printf (" NPC px, id name==% d % s p y=(% d % d) ",
PNode - & gt; Data - & gt; Nid,
PNode - & gt; Data - & gt; The name,
PNode - & gt; Data - & gt; Nx,
PNode - & gt; Data - & gt; Ny);
PNode=pNode - & gt; PNext;
}
}
Void insertNodeAt (NODE, the NODE * int index)
{
}
CodePudding user response:
I'm VS2015, run the following code, enter the id, name, x and y, sequentially input name of collapse, the pop-up error messageCodePudding user response:
You look the Debug mode order step debugging, something wrong?CodePudding user response:
There seems to be wrong in the input data, but I don't know what wrong with reason,,,CodePudding user response:
Single step breakpoint debugging, at least take a look at your first input data, process data has any problem with youCodePudding user response:
# include "stdafx. H"
#include
#include
//NPC structure information
Typedef struct _NPC
{
Char name [20].
Int nx, ny;
Int nid;
NPC};
Typedef struct _NODE
{
NPC * data;
Struct _NODE * pNext;
} the NODE;
NODE * head;//head node
Void invoke the ();
Void queryNode (int nid);
Void printNode ();
Void insertNodeAt (NODE, the NODE * int index);
//enumerated type
Enum SYSMENU
{
ADDNPC=1,//add
QUERY, QUERY//
PRINT,
The QUIT
};
Int main ()
{
Enum SYSMENU input;
The head=NULL;
//
While (1)
{
//display system main menu
Printf (" \ \ \ n1 nNPC management system to add NPC n2 query NPC \ n3 print all NPC information \ n4 interchange exits system \ n ");
The scanf (" % d ", & amp; Input);
//determine which user selects the menu item
The switch (input)
{
Case ADDNPC:
Printf (" \ n you selected 1, add \ n ");
Invoke the ();
break;
In case the QUERY:
Printf (" \ n you select 2, query \ n ");
break;
Case PRINT:
Printf (" \ n you chose 3, print \ n ");
PrintNode ();
break;
In case the QUIT:
Printf (" \ n you chose 4, exit \ n ");
exit(0);
break;
Default:
break;
}
}
system("pause");
return 0;
}
Void invoke the ()
{
//the new node
NODE * pNewNode=(*) malloc (sizeof (NODE));
PNewNode - & gt; Data=https://bbs.csdn.net/topics/* (NPC) malloc (sizeof (NPC));
PNewNode - & gt; PNext=NULL;
//the node assignment
Printf (" please enter the NPC id name nx ny \ n ");
The scanf (" % d % d % d % s ", & amp; PNewNode - & gt; Data - & gt; Nid,
PNewNode - & gt; Data - & gt; The name,
& PNewNode - & gt; Data - & gt; Nx,
& PNewNode - & gt; Data - & gt; Ny);
If (head==NULL)
{
//added directly node
The head=pNewNode;
}
The else
{
//find the last node, add
NODE * pNode;
PNode=head;
While (pNode - & gt; PNext!=NULL)
{
PNode=pNode - & gt; PNext;
}
PNode - & gt; PNext=pNewNode;
}
}
Void queryNode (int nid)
{
}
Void printNode ()
{
NODE * pNode;
PNode=head;
While (pNode)
{
//print node information
Printf (" NPC px, id name==% d % s p y=(% d % d) \ n ",
PNode - & gt; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull