If the user inputs 1 the program will automatically create a new node..How? the maximum that I can do is 2..how to add node?
Code blocks are created by indenting at least 4 spaces
... and can span multiple lines

def *New(def *pHead){

def *temp;
temp = malloc(sizeof(def));

pHead->pNext = temp;
temp->pNext = NULL;

return temp;
}

void plusdata( def *pHead){
char D;
int s,r;
def *pNew, *current;
int count=0,i=0;

do{
printf("Allocate:");
scanf("%d,%c",&r,&D);

if((r == 1)){    
pNew = New(pHead);    
}
if(pNew->pNext == NULL)
printf("Nulling success!\n");


pHead->access.count = 4;
pNew->access.count = 2;


current = pHead;
while (current != NULL){

count++;
printf("%d: %d\n",count,current->access.count);
current = current->pNext;
    }

pNew -> pNext = pHead;


printf("Count: %d\n",count);
printf("again:");
scanf("%d",&s);
count=0;
}while(s == 1);

Perhaps you can create a separate function which adds nodes and call it in your program. Something like this I guess:

    for (int i = 1; i < = n; i ++ ) {
        ptr = new Node;     //create new node
        ptr - > data = i;
        ptr - > next = NULL;
        lastNodePtr - > next = ptr;     // order is important 
        lastNodePtr = ptr;      
    }

new is c++, not c.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.