I am trying to create a linked list that has the user input five values, then displays them. After which the user is prompted to input an additional value and then all the values are displayed again. This is what I have, what is it that I am doing wrong. I am referencing my text book and doing almost the same thing but not getting good results. Thanks for helping me out.
Code:
#include <stdio.h>
struct num
{
int value;
struct num *nextnum;
};
void display (struct num *);
int main ()
{
printf("Enter first value");
scanf ("%d",struct num &n1);
printf("Enter second value");
scanf ("%d",struct num &n2);
printf("Enter third value");
scanf ("%d",struct num &n3);
printf("Enter fourth value");
scanf ("%d",struct num &n4);
printf("Enter fifth value");
scanf ("%d",struct num &n5);
struct num * firtst;
first = &n1;
n1.nextnum = &n2;
n2.nextnum = &n3;
n3.nextnum = &n4;
n4.nextnum = &n5;
n5.nextnum = NULL;
display (first);
printf("Enter sixth value");
scanf ("%d", struct num &n6);
first = &n1;
n1.nextnum = &n2;
n2.nextnum = &n3;
n3.nextnum = &n4;
n4.nextnum = &n5;
n5.nextnum = &n6;
n6.nextnum = NULL;
display (first);
system ("PAUSE");
return 0;
}
void display (struct num *contents)
{
while (contents != NULL)
{
printf("\n%d",contents->value);
contents = contents -> nextnum;
}
return;
}