Thread: cctype functions

  1. #1
    Registered User
    Join Date
    Dec 2003

    cctype functions

    I'm rather new at C/C++ and I'm having trouble understanding how these things work. I'm reading a tutorial on them but I don't understand the return values that I'm getting. Let's use the isdigit() function as an example, the tutorial says:
    The isdigit() function returns non-zero for true and zero for false. If the parameter is not in the domain of the function, the return result is undefined.
    Now suppose that I use the following code:
     int var_one = 1;
     bool var_two = isdigit(var_one);
     cout << var_two << endl;
    The program will output a 0 for false, but var_one is a digit. What am I missing here?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Is false

    is true

    It's for testing characters which you might type in at the keyboard, or read from a text file.

    Eg, if you ask the user to enter a number, and they enter "abc", you can use isdigit() to verify the data entry.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Dec 2003
    Thanks, I see where I was going wrong now -- expected the 1 to be evaluated as an an integer and not as a character :P

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 05:30 PM
  2. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  3. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  4. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  5. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM