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
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.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;
}
How can I do this?
Ps. My english is not perfect, sorry :(
Attachment 15349