title: unexpected out put from char **name, c
body: <p>Am in my way to practice how to use the <a href="http://www.pcre.org/" rel="nofollow">pcre regex library</a>, to match <a href="https://en.wikipedia.org/wiki/Regular_expression" rel="nofollow">regular expression/pattern</a> against a given data/buffer.Then if there is match, i have to load the matched string to may array/list. but, when i print my list/array (using a for loop), the output is unexpected/wrong. pls see how the logic works:</p>
  
  <p>1.first i have to load patterns/regex.....i have a function to do this and returns patterns in an array/list.</p>
  
  <p>2.iterate on each pattern and search for match in a data/buffer....pcre library handles this business.</p>
  
  <p>3.if match exists, push/fill to a list/array</p>
  
  <p>4.print out all matches with in loop</p>
  
  <p><strong>my sample code is:</strong>
  code.c</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;pcre.h&gt;
  #define NUMBER 3
  #define MAX_GROUPS 200
  
  char *data = "Jun 12 05 12:24:48 100.101.102.103 end";
  char **load_patern()
  {
      char **regex_array = malloc (sizeof (char *) * NUMBER);
      regex_array[0] = "(\\w+\\s\\d+\\s\\d+\\s\\d+:\\d+:\\d+)"; //pattern to match date time
      regex_array[1] = "(\\d+.\\d+.\\d+.\\d+)"; //pattern for ip_adress
      regex_array[2] = "(end)";//pattern for "end"
  
    return regex_array;
  }
  
  int main()
  {
          char **patern_list = load_patern();
          int t,i,size,rc,p,re_err_offset,re_vce[MAX_GROUPS];
          char sBuffer[512];
          char *pLasts = NULL;
          pcre *re_compiled;
          pcre_extra *re_extra;
          const char *re_err_str;
          char *token,*logg,*next,*match_str;
  
          char **struct_list = malloc (sizeof (char *) * NUMBER);
          for(t=0;t&lt;3;t++) //3 is number of patterns, patern_list size
          {
              snprintf(sBuffer, sizeof(sBuffer), "%s",data);
              pLasts = sBuffer;
              re_compiled = pcre_compile(patern_list[t], 0, &amp;re_err_str, 
  
  &amp;re_err_offset, NULL);
                  re_extra = pcre_study(re_compiled, 0, &amp;re_err_str);
                  next = pLasts;
                  size = strlen(pLasts);
                  rc = pcre_exec(re_compiled, re_extra, next, size, 0, 0, re_vce, MAX_GROUPS);
                  if(rc&gt;0) //if match exists
                  {
                      next[re_vce[3]] = '\0';
                      match_str = next + re_vce[2];
                      struct_list[t] = match_str;
                      printf("data at [%d]:%s\n",t,struct_list[t]);//this prints correctly
                  }
              }
  //but,here am trying to print each match stored in struct_list[], but it fails to display correctly.
              for(p=0; p&lt;3; p++)
              {
                  printf("loop_one: [%d]----%s\n",p,struct_list[p]);
              }
          return 0;
      }
  </code></pre>
  
  <p>The out put from a loop iterating on p,should be:</p>
  
  <pre><code>loop_one: 0----Jun 12 05 12:24:48
  loop_one: 1----100.101.102.103
  loop_one: 2----end
  </code></pre>
  
  <p>any thing i miss? </p>