Thread: Extracting data from a string..

  1. #16
    C/C++ Learner & Lover
    Join Date
    Aug 2008
    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?

  2. #17
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    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.

  3. #18
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Visalia, CA, USA
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  3. Errors
    By Rhidian in forum C Programming
    Replies: 10
    Last Post: 04-04-2005, 12:22 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM