Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to write a function that deletes a node
    text
    copied!<p>I was trying to write a function that deletes a node from the linked list, though I was having trouble.</p> <p>Here is my algorithm:</p> <ul> <li>Get the name of the node that I want to delete (every node has 3 details in it: name/age/gender)</li> <li>Then I find its place in the list</li> <li>and then I pass it forward</li> </ul> <p>For example</p> <blockquote> <p>Friend -> next = friend -> next -> next..</p> </blockquote> <p>Though I need to find the first node in the linked list, and I'm not sure how to get to it. This is what I've written:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include &lt;stdlib.h&gt; typedef struct friend { char *name; int age; char gender; struct friend* next; }friend; void node_delete(friend* delete) { friend* temp = malloc(sizeof(friend)); char name[256]; int i = 0, j =0; // Not being used, though I'd use it printf ("Please enter the friend's name you want to delete: \n"); fgets (name, 256, stdin); // Getting the name of the person the user wants to delete fgets (name, 256, stdin); while (0 == (strcmp(temp -&gt; next -&gt; name, delete -&gt; next -&gt; name))) // As long as the // name doesnt match, it'll go to the next name in the linked list { temp = friend -&gt; next; // Going to the next name in the linked list } temp -&gt; next = temp -&gt; next -&gt; next; // Replacing the node with the node after it.. // for ex. if I have 1 -&gt; 2 -&gt; 3, it'll be 1 -&gt; 3 free (delete); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload