Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In your insert function, you are useing</p> <pre><code>newnode-&gt;next = prev-&gt;next; prev-&gt;next = newnode; </code></pre> <p>use like</p> <pre><code>newnode-&gt;next = temp; prev-&gt;next = newnode; </code></pre> <p>[EDIT]</p> <p>Use your insert function like this.</p> <pre><code>void insert() { newnode = (struct node*) malloc(sizeof(struct node)); printf("Enter the Name: "); scanf("%s", &amp;name); strncpy(newnode-&gt;nm, name, 10); newnode-&gt;next = NULL; if (list == NULL ) { list = newnode; } else if (strncmp(name, list-&gt;nm, 10) &lt; 0) { newnode-&gt;next = list; list = newnode; } else { temp = list; prev = NULL; // prev is a global variable, So assign it to NULL each time, Otherwise it will keep old value. while (temp != NULL) { if (strcmp(name, temp-&gt;nm) &gt;= 0) { prev = temp; temp = temp-&gt;next; } else { break; } } newnode-&gt;next = temp; prev-&gt;next = newnode; } } </code></pre> <p>Now do remember one thing, In your code,</p> <ol> <li><p>in main() your are doing</p> <p>choice == 'y'; that is not assignment. You should use</p> <p>choice = 'y';</p></li> <li><p>in your main(), in do{}while() your are using</p> <p>while (choice = 'y' &amp;&amp; choice != 'n'); choice ='y' is assignment, not comparison. use like this</p> <p>while (choice == 'y' &amp;&amp; choice != 'n');</p></li> <li><p>in main(), you are using </p> <p>scanf("%s", &amp;choice); // choice is a char, you are trying to have string (%s) here. That will memory corruption So use it like this,</p> <p>choice = getche();</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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