Thread: Line matching

  1. #16
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    strtol takes three arguments:
    1) a string.
    2) a base (can be zero for "automatic" -> anything starting with 0x is hex, starting with 0 -> octal, everything else is treated as decimal).
    3) a pointer to a pointer to char for "where strtol stopped", which can be NULL if you don't care.

    So to use it, we could do:
    Code:
    char *endPtr;
    long x;
    char str[] = "123456";
    
    x = strtol(str, 0, &endPtr);
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #17
    Registered User
    Join Date
    Jun 2009
    Posts
    486
    Cool, thanks. So I can simply test that the pointer is NULL before incrementing the count.

  3. #18
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I don't think that you can check that the pointer itself is NULL -- you'll always get a real pointer back. You need to check that the pointer points to a null character (i.e. \0).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer and Polymorphism help.
    By Skyy in forum C++ Programming
    Replies: 29
    Last Post: 12-18-2008, 09:17 PM
  2. Printing Length of Input and the Limited Input
    By dnguyen1022 in forum C Programming
    Replies: 33
    Last Post: 11-29-2008, 04:13 PM
  3. Finding carriage returns (\c) in a line
    By JizJizJiz in forum C++ Programming
    Replies: 37
    Last Post: 07-19-2006, 05:44 PM
  4. Adding Line numbers in Word
    By Mister C in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 06-24-2004, 08:45 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM