Witam chciałbym dodać do listy elementy, zrobiłem taki kod ale coś jest nie tak..
#include <stdio.h>
#include <stdlib.h>
struct node{
int w;
struct node *next;
};
void filllist(struct node *list)
{
int i;
struct node *p;
for(i = 0; i < 10 ; i++){
p = (struct node*) malloc(sizeof(struct node));
p->w = i;
p->next = list;
list = p;
}
}
void printlist(struct node *list)
{
struct node *p;
p = list;
while(p != NULL )
{
printf("%d", p->w);
p = p->next;
}
}
int main()
{
struct node *list = (struct node*) malloc(sizeof(struct node));
list->next = 0;
list->w = 5;
filllist(list);
printlist(list);
return 0;
}
Wyświetla tylko 5..