Line matching

This is a discussion on Line matching within the C Programming forums, part of the General Programming Boards category; strtol takes three arguments: 1) a string. 2) a base (can be zero for "automatic" -> anything starting with 0x ...

  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
    452
    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,185
    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).

Page 2 of 2 FirstFirst 12
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, 06: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, 09: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, 02:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21