Dear Programmers,

i have a linked list problem. I have have a number, for example 197, and put it in an array----> [0] = 1 , [1]=9, [2]=7

So far so good. Now, i want to make a linked list of these numbers. I have made the following code:

The problem is, that it's nog working. I think there is something wrong in the linking....

Code:
```
int length = 0;
char buffer[50];
itoa(num, buffer, 10);

//find the length of the charater number
for(int i=0; i<10; i++){
if(buffer[i] == '\0'){
length = i;
}
}
printf("%d\n",length);

struct node *lp;

if(length>0){									//allocate memory for the first elemement.
head =(struct node *) malloc(sizeof(struct node));
}

for(int i=1; i<length;i++){				//because 0 is done above)
//lp->next = (node*)malloc(sizeof(struct node));
lp->next =(struct node *) malloc(sizeof(struct node));
//lp =(struct node *) malloc(sizeof(struct node));
lp = lp->next;
lp->data = buffer[i];
printf("%c\n",lp->data);
}

/*	printing the entire list */
while( lp != NULL )					//continue whilst there are nodes left
{
printf("%c\n", lp->data );		//print out the current node
lp = lp->next;					//goto the next node in the list
}

2. By the looks of it your problem lies in the following code:
Code:
```	for(int i=1; i<length;i++){				//because 0 is done above)
//lp->next = (node*)malloc(sizeof(struct node));
lp->next =(struct node *) malloc(sizeof(struct node));
//lp =(struct node *) malloc(sizeof(struct node));
lp = lp->next;
lp->data = buffer[i];
printf("%c\n",lp->data);
}```
Consider one iteration of this loop. Initially lp and head are the same. You then allocate more memory for the next node using malloc - This bit is fine. You then reassign lp to be the next one in the chain using lp = lp->next, which is fine. Then you assign some content to the structure and print it to the screen, which is ok again, but then you assign the pointer head->next to zero, which is not fine.

This basically creates a linked list and then removes the pointer from the 'head' structure in the list. Do you now understand the problem? I think what you mean is 'lp->next = 0', not 'head->next = 0'.

Also, in this bit:
Code:
```/*	printing the entire list */