validation

This is a discussion on validation within the C Programming forums, part of the General Programming Boards category; n1 and n2 are two ints ... If the input is legal but the entered n1 or n2 or the ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    8

    validation

    n1 and n2 are two ints ...
    If the input is legal but the entered n1 or n2 or the calculated output value is out of the range of an unsigned long int value, then the corresponding output should be
    out of range

    how would this be possible with scanf?

  2. #2
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    I don't think you can tell with scanf.

    If you want better validation, read in the input as a string (using fgets for example), and use strtol to convert it to a long. You can then check for range errors.
    Last edited by cwr; 02-19-2006 at 11:08 PM.

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    8
    I didnt quite get that ... would you please at least post some code...

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Read the handy dandy FAQ on getting a number from the user. Use your handy dandy browser to point yourself at a search engine, type in strtol, and surprise yourself that you can find the answer on your own.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. validation of TextBoxes!?
    By c9dw2rm8 in forum C# Programming
    Replies: 1
    Last Post: 04-01-2008, 06:19 PM
  2. set validation
    By jmarsh56 in forum C++ Programming
    Replies: 4
    Last Post: 12-13-2005, 07:49 AM
  3. DATE <TIME.H> data validation
    By bazzano in forum C Programming
    Replies: 4
    Last Post: 08-07-2005, 01:10 AM
  4. validation routine help plz
    By rajesh23 in forum C Programming
    Replies: 8
    Last Post: 09-23-2003, 07:21 AM
  5. [C#] Validation class for events?
    By gicio in forum C# Programming
    Replies: 4
    Last Post: 01-03-2003, 11:19 AM

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