Thread: Help for my code

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2018
    Posts
    21

    Help for my code

    Hello everyone,
    I'm new entry here, my name is Jacopo, from Italy.
    I'm trying study c language and I have write a code to make a list but now I need some help for this.
    So, this is not exactly my code, this is only a test code that I did to check memory address of list elements

    Code:
    #include <stdio.h>
    
    
    struct Element {
        int info;
        struct Element *next;
        struct Element *prev;
    };
    
    
    struct Element New_Element(int info);
    
    
    int main(int argc, char **argv)
    {
        int a, c;
        printf("How many elements do you want put in? ");
        scanf("%d", &c);
        for (int h = 0; h < c; h++) {
            printf("Insert a: ");
            scanf("%d", &a);
            struct Element e = New_Element(a);
            printf("Elemento%d struct address: %p \n\n", h, &e);
        }
        return 0;
    }
    
    struct Element New_Element(int info) {
        struct Element e = {info, NULL, NULL};
        return e; 
    }
    My issue is that the compiler assign every time the same memory location to each elements (see image below). This isn't good to me because I need to have a pointers that point different elements and therefore different memory address.
    How can I do this?
    Ps. My english is not perfect, sorry

    Help for my code-capture-png
    Last edited by Jacopo; 02-16-2018 at 05:28 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-19-2012, 01:58 PM
  2. Replies: 14
    Last Post: 04-01-2008, 02:23 AM
  3. producing c/c++ code from flowcharts,pseudo code , algorithims
    By rohit83.ken in forum C++ Programming
    Replies: 3
    Last Post: 02-20-2008, 07:09 AM
  4. Having trouble translating psudeo-code to real-code.
    By Lithorien in forum C++ Programming
    Replies: 13
    Last Post: 10-05-2004, 07:51 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM

Tags for this Thread