test for int

how can you test to make sure an integer was entered rather than say a character?

thanks!

Comments

  • : how can you test to make sure an integer was entered rather than say a character?
    :
    : thanks!
    :
    check each character entered with the isdigit() macro.


  • thanks for replying... so would i read in the entry as a string and then go one by one using isdigit()? the background is that if the user enters an 'a' rather than an integer, i want to make the value of the integer 0...

    thanks

    : : how can you test to make sure an integer was entered rather than say a character?
    : :
    : : thanks!
    : :
    : check each character entered with the isdigit() macro.
    :
    :
    :

  • : thanks for replying... so would i read in the entry as a string and then go one by one using isdigit()? the background is that if the user enters an 'a' rather than an integer, i want to make the value of the integer 0...
    :
    : thanks

    Yes, I would enter it as a string as you mentioned, but if something other than a digit is entered you should display an error message and make him enter the whold thing again. In any event you should not just argibrarily make the non-digit character a zero because that could be wrong too.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories