title: unusual behaviour of strtol function when used twice in function
body: <p>In below code , I have been facing some unusual behavior of strtol function as it doesn't return the last value associated with string passed as a 2nd parameter to the expcmp function.  I don't  see same behavior with first string . </p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  #include&lt;stdlib.h&gt;
  
  int16_t  expcmp( char* exp_cmp,char* exp_val)
  {
  
      char DELIM='.';
  
      int16_t rc=1;
  
      char *p=NULL;
      char *temp=NULL;
      if(strlen(exp_cmp)&gt;0)
          {
              p=(char*)malloc(sizeof(strlen(exp_cmp)+1));
              strcpy(p,exp_cmp);
              printf("p=%s\n",p);
          }
      if(strlen (exp_val)&gt;0)
          {
              temp=(char*)malloc(sizeof(strlen(exp_val)+1));
  
              strcpy(temp,exp_val);
              printf("temp=%s\n",temp);
          }
  
      while (*temp) {
          if (isdigit(*temp)) {
              int16_t val = strtol(temp, &amp;temp, 10);
              printf("temp=%d\n",val);
          }
          else if(*temp!=DELIM)
              {
                  rc=0;
                  break;
              }
          temp++;
      }
  
      while (*p) {
          if (isdigit(*p)) {
              int16_t val = strtol(p, &amp;p, 10);
              printf("val=%d\n",val);
          }
          else if(*p!=DELIM)
              {
                  rc=0;
                  break;
              }
          p++;
      }
  
      return rc;
  
  }
  
  int main()
  {
      int ret_code;
      ret_code=expcmp(".1.7.8.29.41.8153",".1.7.8.29.41.8153");
      return 0;
  }
  </code></pre>