More strtod troubles

This is a discussion on More strtod troubles within the Windows Programming forums, part of the Platform Specific Boards category; Some time ago I got some help and the suggestion was given to use strtod to validate floating point input ...

  1. #1
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    Question More strtod troubles

    Some time ago I got some help and the suggestion was given to use strtod to validate floating point input from a dialog box.
    Validate Float Logic?

    Now, I am well on my way writing this program when I realize that the user could very well wish to input zero and since the strtod function returns zero on failure this is probably not the best solution.

    Why in the world would it return zero if zero could be a valid input? Am I missing the point?
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,630
    What you had originally to check the validity of user input was fine - checking valid input and converting that input to a double are two different things. I would use both.
    Code:
    if (is_valid_double(pbuffer))
    {
       double val = strtod(pbuffer);
       ...
    }
    Don't forget about negative numbers....if that's valid input.


    gg
    Last edited by Codeplug; 03-09-2003 at 05:49 AM.

  3. #3
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    Thanks Codeplug!

    ...for keeping me on the right track.
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with strtod
    By robert777 in forum C Programming
    Replies: 11
    Last Post: 11-03-2008, 11:49 AM
  2. Replies: 4
    Last Post: 01-15-2006, 04:14 AM
  3. How does strtod manage to parse?
    By seedpress in forum C Programming
    Replies: 4
    Last Post: 03-23-2005, 05:03 PM
  4. Help with strtod and fgets..
    By Gugge in forum C Programming
    Replies: 2
    Last Post: 05-15-2002, 02:21 PM
  5. having troubles
    By neandrake in forum C++ Programming
    Replies: 7
    Last Post: 03-07-2002, 08:31 PM

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