String to unsigned long conversion I'm trying to use strtoul() to convert an Arduino String to an unsigned long (like the return of millis();) using the following code snippet:

unsigned long foo (String time)
{
  unsigned long mili;
  char Tim[9]="";
  uint16_t timsize = time.length()+1;
  char TIM[timsize];
  time.toCharArray(TIM,timsize);
  mili=strtoul(TIM,timsize,10);
  return mili;
}


The code seems to work. However, I'm getting the following warning:


  invalid conversion from 'uint16_t {aka unsigned int}' to 'char**' [-fpermissive] mili=strtoul(TIM,timsize,10);




My question is twofold:


Is there a better way to convert a String to unsigned long without first converting to a C string?
If not, how can I eliminate this error?
Arduino String class provides method c_str(). So you don't have to convert it to C string, as it's already stored as a C string internally.

And as mentioned in comments, the second parameter of strtoul is:


  endptr
      Reference to an object of type char*, whose value is set by the function to the next character in str after the numerical value.
      This parameter can also be a null pointer, in which case it is not used.


Basically you can reduce whole foo to the:  return strtoul(time.c_str(), NULL, 10);