Thread: Problem using function strtol/strtoul

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    17

    Question Problem using function strtol/strtoul

    I am using the function strtol to convert a string to long no. and I am using this long no. to address a port.

    I am fetching this string from the edit box of a window.

    I am facing a very peculiar type of problem.

    My port address is hex 200.

    When in the edit box I place 200 the system verifies that the port is addressed successfully(which should be the case).

    When I place 20G in the edit box again the port verifies successfully. (I feel that strtol converts it to 20)

    But if I change the port address in the program code from 200 to 20 I receive a verification failed message.(which is right as the port address is not 20 but 200)

    What is the problem in fetching the string (I am geting it as Cstring type) or converting it to long using strtol.

    juhi

  2. #2
    William
    Guest
    strtol stops when a char isn't a digit any more, that why "20G" gives 20. For the rest, are you sure you've got the base right (the base determines what a valid digit is)? I've used strtol (and others like it) with success... Post a peace of code which doesn't work please.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  3. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  4. Problem with function pointers
    By vNvNation in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2004, 06:49 AM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM