-3

I am trying to convert a substring to integer but I am getting this output

    int main()
{
    char buf[50] = "210-567-12-2040-34567890.txt";
    char* pStart = buf;
    char* pCurrent = buf;
    while(*pCurrent != '\0')
    {
        if (*pCurrent == '-' || *pCurrent == '.') 
        {
            uint32_t val = strtoul(pStart, NULL, 10); 
            pStart = pCurrent+1;
            printf("%ul\n",val);
        }
        ++pCurrent;
    }
    return 0;
}

I am getting this output

210l                                                                                                                                   
567l                                                                                                                                   
12l                                                                                                                                    
2040l                                                                                                                                  
34567890l

Why is there a l in it?

sephora
  • 21
  • 1
  • 7

1 Answers1

0

Some of the answers here are what you're looking for: What is the difference between char s[] and char *s?

Short answer is there's no difference between the two as a function argument. You can pass the char* pStart variable into strtoul the same as you'd pass the char str[20] variable into it. This will make it read the string directly from whatever memory address pStart points to, no need to copy into an array first.

sudo
  • 5,604
  • 5
  • 40
  • 78