Link List

Howdy,
I wrote the following program to accept integers then disply the linked list. seems to be working fine, except it disply punch of one's (1) and I dont know why, can I get some help please?? Thank you
#include <stdio.h>
struct number_list
{
int number;
struct number_list *nextnumber;
};

main()
{
int numbers;
struct number_list t1 = {scanf("%d", &numbers)};
struct number_list t2 = {scanf("%d", &numbers)};
struct number_list t3 = {scanf("%d", &numbers)};
struct number_list t4 = {scanf("%d", &numbers)};
struct number_list t5 = {scanf("%d", &numbers)};
struct number_list t6 = {scanf("%d", &numbers)};
struct number_list t7 = {scanf("%d", &numbers)};
struct number_list t8 = {scanf("%d", &numbers)};
struct number_list t9 = {scanf("%d", &numbers)};
struct number_list t10 = {scanf("%d", &numbers)};
struct number_list *first;

first = &t1;
t1.nextnumber = &t2;
t2.nextnumber = &t3;
t3.nextnumber = &t4;
t4.nextnumber = &t5;
t5.nextnumber = &t6;
t6.nextnumber = &t7;
t7.nextnumber = &t8;
t8.nextnumber = &t9;
t9.nextnumber = &t10;
t10.nextnumber = NULL;
{
int contents = 0;
while (contents <1)
{      
printf ("\n %d\n %d\n %d\n %d\n %d\n %d\n %d\n %d\n %d\n %d\n\n",
first->number, t1.nextnumber->number, t2.nextnumber->number,t3.nextnumber->number, t4.nextnumber->number, t5.nextnumber->number,
t6.nextnumber->number, t7.nextnumber->number, t8.nextnumber->number,
t9.nextnumber->number);
contents++;
}
return 0;
}
}
kkanealAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tdubroffCommented:
Scanf returns the number of parameters it read.  In this case it reads 1 number every time.  Therefore, first do the scanf() then create your struct with the numbers value.

-Ted
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.