title: error using pointers in functions c++
body: <pre><code>#include &lt;iostream&gt;
  using namespace std;
  #include &lt;string&gt;
  #include &lt;map&gt;
  
  typedef struct node{
      char a;
      map&lt;char , node*&gt; b;
  }node;
  
  node a[26] ; 
  
  void add(string s){
      node *prev = &amp;(a[s[0]-'a']);
      int i = 0;
      int len = s.length();
      for(i = 1; i &lt; len; ++i){        
          map&lt;char,node*&gt;::iterator it = ((*prev).b).find(s[i]);
          if(it != ((*prev).b).end()){
              prev = it-&gt;second;
          }
          else{
              cout &lt;&lt; (*prev).a &lt;&lt; endl;
              node pt;
              pt.a = s[i];
              ((*prev).b)[s[i]] = &amp;pt;
              prev = &amp;pt;
          }
      }
  }
  
  int main(){
      string s = "helloworld";
      string t = "htllothis";
      int i = 0 ;
      for(i = 0;i &lt; 26;++i){
          a[i].a = 'a'+i;
      }
      add(s);
      add(t);
      return 0;
  }
  </code></pre>
  
  <p>I am trying to implement tire datastructure using map and char but <code>cout&lt;&lt; (*prev).a</code> is printing some other chars. What is the mistake I have done?</p>