Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9098791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:26:50+00:00 2026-06-17T00:26:50+00:00

I have to make for homework 2 linked lists, put integers given from the

  • 0

I have to make for homework 2 linked lists, put integers given from the user in the first and then put the result=x^3 for each integer of the first to the second list. In the following code, I am trying to print what I put in the first list, reading with scanf. I haven’t yet understood why can’t I print by this way. Could you please explain? Thanks in advance!! The problem is that I print only the last element and 0… :s

Code:

#include <stdio.h>
#include <stdlib.h>

struct L1 
{
    int x;
    struct L1 *next1;
};

struct L2 
{
    int x,i,v;
    struct L2 *next2;
};

int main()
{
    int i,N;
    struct L1 *root1; 
    struct L2 *root2;
    struct L1 *conductor1;  
    struct L2 *conductor2;

    root1 = malloc(sizeof(struct L1));  
    root2 = malloc(sizeof(struct L2));
    root1->next1=0;
    conductor1 = root1;
    printf("Dwste arithmo N");
    scanf("%d",&N);
    printf("\nDwse arithmo");
    scanf("%d",&conductor1->x);
    printf("%d",conductor1->x);

    for(i=0; i<N; i++)
    {
        conductor1->next1 = malloc(sizeof(struct L1));
        printf("\nDwste arithmo");
        scanf("%d",&conductor1->x);
        conductor1->next1=0;
    }
    conductor1 = root1;
    while (conductor1 != NULL)
    {
        printf("\n%d",conductor1->x);
        conductor1=conductor1->next1;
    }

    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T00:26:52+00:00Added an answer on June 17, 2026 at 12:26 am

    In the for loop you are never changing the value of conductor1. So it will always point to the head node, and you will always overwrite the fields of that node. You need to add conductor1=conductor1->next1; after allocating the new node to advance to the next node in each iteration.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have make a messaging system in which user can send messages to each
So I have a homework to make a flowchart of an algorithm printing first
I have a linked list question that stems from this homework prompt I am
I have to make a conditional in ash, that depends on result of two
I have a homework assignment, and i am finished other then one question (see
I have some homework for my school and I have to make a snake
Note: This is a homework assignment. I have two classes, one inherits from the
As part of my homework, I need to make a program that requires user
First I want to make it clear that this is a homework based question.
This is an excerpt from homework. Prog This datatype should have only one constructor

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.