Help with nested structs in C

1

I was creating a list with C and using a struct , after finishing I tried to see what was changing with a nested struct , I created two structs basic, one getting only one value, and other receiving this first and a pointer to the same type.

So I started having a data insertion problem, in my list there are two methods of inserting data, one that inserts at the beginning of the list and another that inserts at the end of the list, both worked in the same way (with their particularities of course) and I realized that when entering a data it received, but when entering the second value it changed the first data to become equal to the second and so on always changing all to the last data inserted (would be a pointer problem?)

I then took the insert method at the beginning and changed the structure of it to see if I could find another way to solve the problem, finally creating another problem, follow the link with the code: C List

  

Note 1: Option 3 that inserts at the end causes the problem that I reported.

Edit: 05/24/16 19:25

On the insere_inicio() function: It is working as it should, ie inserting distinct values, and how I will adopt for the insere_final() function, however I have another problem that I am not sure how to solve, I would like to create chars chains ( strings ) however I am not able to do so, as I do:

scanf(" %s", &novo->person.name);

It causes a ERROR in the program, so I had to replace everything with %c , however I would like to read a whole name, not just a letter.

    
asked by anonymous 24.05.2016 / 06:34

1 answer

0

Problem solved. Link: Solution working properly I chose to use an array of char instead of pointer (I confess I do not know what changes between them in this usage).

I created a method called "aloca ()" that is now receiving the information from the first struct and then correctly inserting the data into the second struct, revealing that the problem was merely a pointer that was being manipulated directly .

    
25.05.2016 / 08:54