title: C++ list program freeze when i call a function
body: <p>This code must insert character 'p' before character 'q' how many times 'q' appear in list. </p>
  
  <p>When I call function <code>insert_before</code> (<code>insert_before('q','p')</code> ) my program freezes. I don't write all the code here. The rest of the program works fine.  </p>
  
  <pre><code>struct node
  {
     char character;
     node* next;
  };
  node *fisrt , *end;
  void insert_before(char val_search,char val_inserted)
  {
     node *c,*a;
     c=first;
     do {
        if (c-&gt;next-&gt;character==val_search)
        {
            a= new node ;
            a-&gt;character=val_inserted ;
            a-&gt;next=c-&gt;next;
            c-&gt;next=a;
            c=c-&gt;next; 
        }
        else 
            c=c-&gt;next; 
     } while (c) ; 
  }
  </code></pre>