c - Linked list structures initialized in functions not being assigned properly -


I'm sure that has been asked before, but not after searching this website or anyone else for it May be quite late.

I am having trouble getting the values ​​of the structures that I am creating in a function and am amending I code looks like this:

  Structure Node {char name [35]; Int employee id; Structure node * next; } Typedef struct node employee; Insert zero in order (employee * head, employee * curu) {if (head == faucet) {* curr- & gt; Next = * head; * Head = * curr; } And {if ((Head-> Employee ID  Employee ID) & amp; amp; amp; amp; amp; Employee;> employee ID & Lt; head-> Next-> employee id)) * * Curr- & gt; Next = head & gt; Next; * head-> gt; Next = * curr; } And insertInOrder (head-> next, curr);}}} zero addEmployee (four names [employee] * head, employee * curr) {int id; scanf ("% d", & amp; id); curr = malloc (size (employee); strcpy (curr- & gt; name, name); Curr-> employee id = id; insertInOrder (head, curr);} ent main (zero) {four names [35] ; int quit = 1; Employee * head, * curr; head = null; Printf ("Enter data about books: \ n"); while (left) {scanf ("% [^ \ n]% * c (title); if (title [0]! = '#') {adbook (name, head, cor);} Else {quit = 0;}}   

My debugging During, my Ods turn into all my work, but once I want all the data to return to main return, all the variables are empty I know that the way I am using or passing points I have something to do with it, but when I look at the code, then I'm coming to a logical conclusion what I should do, what I want, please, someone tells me that my algorithm fault

AdBook

book < / Code> but you are indicating the type of employee

edit:

Then, first you have to type * curr-> Next = * head this curr-> Next should be = head . In addition, head-> next can be redundant which is not being checked. Finally, head should always be indicated at the beginning of the list.

Edit 2:

The following code should work. head always indicates to start the list. To do this, we have to pass the address of the head indicator. We need to do this because we will modify the address of head .

I have cleared some things too.

  Zero InsertInOrder (employee ** head, employee * curr) {if (* head == NULL) {// We are inserting the first element * head = curr; } And if ((* head) -> Next == faucet) {// This is the second element: We either put it in front of the head or before the head if ((* head) -> employee ID & lt ; Curr- & gt; employee id) {(* head) - & gt; Next = curr; } And (curr-> next = * head; * head = curu; (* head) -> gt; next = null;}} else {// we try to find the best place to insert curr Repeat through the list. Employee * temp = * head; while (temp-> Next! = NULL) {If ((temp-> Employee ID & lt; curr- & gt; employee ID) & amp; ; amp; amp; amp; & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; employee id & lt; temp- & gt; next- & gt; Employee id) {curr-> next = floating-> next; temp-> next = curr; break;} temp = temp-> next;} // curr bus Big id, so it is inserted at the end if (temp-> next == NULL) temp-> next = curr;}} zero addemployee (four names [], employee ** head) {int id ; Printf ("Enter ID \ n"); Scanf ("% d", & amp; id); employee * curr = malloc (size); Strcpy (curr- & gt; name, name); Curr -> Employee ID = ID; Curr- & gt; Next = Faucet; InsertInOrder (head, curr);} Int main (zero) {int quit = 1; employee * head = zero; Four titles [100]; Printf ("Enter data about employees: \ n"); While (left) {scanf ("% s", title); If (title [0]! = '#') AddMployee (title, and head); And break; } Return 0; }    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -