Search code examples
cstrtol

Using strtoul in C


In C, why does

strtoul(argv[1])

just doesn't work? It looks like more parameters are needed but I can't prevent how long the number will be.

Thanks!

p.s. (argv[1] is properly setted).


Solution

  • Because you're calling it with the wrong number of arguments. Try

    strtoul(argv[1], 0, 0);
    

    Or if you want to enforce base-10 only:

    strtoul(argv[1], 0, 10);
    

    Be sure you included <stdlib.h> too!