-
Mmm.. the man pages for strtol, says that the number needs needs some white spaces and a + or - sign.. is that necessary?, and what about the end of the number, if I don't want to specify one, NULL is ok right? and.. what does the last argument is for?
-
No, the man pages state that it can have whitespace and a + sign, not that it must. And passing NULL should be fine. The last argument is the base of the number given -- so 2 means "read a binary number", 11 means "read a number in base 11", and so on. If you make it 0, it means "read a number like it's a C constant", so 0whatever is octal and 0xwhatever is hex.
-
The last argument is the whole reason I even used strtol at all ;) Taking the last argument into consideration you could parse values like 0777 as 511 or 0x000AEF10 as 716560. But the code I posted doesn't automatically just know how to do that. It lazily detects any character and calls the whole parameter a string. So to avoid that you'd have to have it preprocess each variable for octal or hexidecimal numbers.