It doesn't link the list here is the code I don't know how to fix it !
Code:
#include <iostream>
#include <conio.h>
#define UINT unsigned int
using namespace std;
struct SCPU
{
char sCommand[256];
UINT uPriority;
SCPU *pNext;
};
SCPU* AddInstruction(char *sCommand,UINT uPriority)
{
int iCounter;
SCPU *pCurrNode;
pCurrNode = new SCPU;
for(iCounter = 0;sCommand[iCounter];iCounter++)
pCurrNode->sCommand[iCounter] = sCommand[iCounter];
pCurrNode->sCommand[iCounter] = 0;
pCurrNode->uPriority = uPriority;
pCurrNode->pNext = NULL;
return pCurrNode;
}
void insert(SCPU *pointer, int data)
{
/* Iterate through the list till we encounter the last node.*/
while(pointer->pNext!=NULL)
{
pointer = pointer -> pNext;
}
/* Allocate memory for the new node and put data in it.*/
pointer->pNext = (SCPU *)malloc(sizeof(SCPU));
pointer = pointer->pNext;
pointer->uPriority = data;
pointer->pNext = NULL;
}
int main(void)
{
char SName[] = "abcde123";
SCPU *pHead = new SCPU;
SCPU *pTemp = NULL,*pTemp2;
pHead->pNext = NULL;
for(int i = 0; i < 10;i++)
{
pTemp = AddInstruction("hello",i);
if(i == 0)
pHead->pNext = pTemp;
pTemp = pTemp->pNext;
}
while(pTemp){
cout << "name is " << pTemp->sCommand << " and priority is " << pTemp->uPriority;
pTemp = pTemp->pNext;
_getch();
}
_getch();
return 0;
}