As the title says I need to write a function which fill a list with int typed by the user, and later on print them, but i'm having troubles with the insert function, which does not actually put the values typed in the list. Here's the code:
the typedefs:
typedef struct list_element {
int value;
struct list_element *next;
} item;
typedef item *list;
and the functions:
list lins(list l)
{
int i;
list root = NULL;
printf("inserire dati ('0' per terminare):\n");
do
{
scanf("%d", &i);
l = (list)malloc(sizeof(item));
l->value = i;
l->next = root;
root = l;
} while (i != 0);
return l;
}
void showlist(list l)
{
printf("lista completa:\n");
while (l != NULL)
{
printf("%d ", l->value);
l = l->next;
}
printf("\n");
}
Sorry if my code is poorly written but I'm having a hard time understanding the concept of lists.
Edit: added functions calls
main()
{
lins(l);
showlist(l);
}
Edit 2: here's the output of the code:
Edit 3: Here's the sample of code my professor give us to work with lists:
http://www.mediafire.com/file/wj152pw1ojkxf1j/10a_-Liste-_2018.pdf