c++ insertion node in single linked list
<p>Can someone help me understand what I'm doing wrong. I need to insert a character into a linked list.</p>

<p>It takes an input like a name of person, than it reverses it.
then it tells user to choose a position to add a character.</p>

<pre><code>void insert_char(Node* plist, char x, int p){
  Node* d=plist;
  for (int i=1; i&lt;p and 0!=d; i++)
    d=d-&gt;next;
  if (0 !=d)
    d-&gt;x=x;
</code></pre>

<p>However, this code changes the character, not adds it.</p>

<p>UPDATE:</p>

<p>I can't still figure it out.</p>

<pre><code>void insert_char(Node* plist, char x, int p){
    Node* d=plist;
    Node* d2=0;
    for (int i=1; i&lt;p and 0!=d; i++)
        d2-&gt;next=d-&gt;next;
    d-&gt;next=d2;
    if (0 !=d)
        d2-&gt;x=x;
    return;
}
</code></pre>

<p>I am getting a segmentation error.</p>

<p>Ok, so i figured out, what i really wanted. Thanks for help</p>

<pre><code>  void insert_char(Node* plist, char x, int p){
  Node* d=plist;
  Node* d2= new Node();
  for (int i=1; i&lt;p and d; i++)
    d2-&gt;next=d-&gt;next;
    d-&gt;next=d2;
  if (0 !=d)
    d2-&gt;x=x;
  return;
}
</code></pre>
