0

I convert string to unsigned long like this code.

String t = "1667451600";
unsigned long ret;
ret = strtoul(t,NULL,10);

It show error like this.

test:122:19: error: cannot convert 'String' to 'const char*'
  122 |     ret = strtoul(t,NULL,10);
      |                   ^
      |                   |
      |                   String

exit status 1
cannot convert 'String' to 'const char*'

How to canvert string to unsigned long in C ?

user58519
  • 579
  • 1
  • 4
  • 19
  • 1
    String is an object I'm guessing? , strtoul wants a char pointer. String isn't standard C. You should be able to access the char pointer directly inside the String object. – Irelia Mar 11 '22 at 04:06
  • 3
    There is no `String` in standard C. Please provide a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) that details the type definition for `String` (or some documentation thereof). – Oka Mar 11 '22 at 04:36
  • From the error message this looks more like C++ than C. – user17732522 Mar 11 '22 at 04:39
  • 1
    Your question will get closed soon unless you explain what 'String' is or provide a complete small example of its being used – pm100 Mar 11 '22 at 05:09

1 Answers1

3

String is not a standard type in C. Try this:

char *t = "1667451600";
unsigned long ret;
ret = strtoul(t,NULL,10);
SGeorgiades
  • 1,771
  • 1
  • 11
  • 11