Search code examples
ctype-conversionstrtoul

Cannot convert string to unsigned long in C


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 ?


Solution

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

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