Thread: isdigit()

  1. #1
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534

    isdigit()

    When I run this program:
    Code:
    #include <stdio.h>
    #include <ctype.h>
    
    int main(void)
    {
      int c = 0;
      printf("Enter a digit between 0 - 9\n");
      fflush(stdout);
      c = getchar();
      printf("The value from isdigit: %d\n", isdigit(c));
      return 0;
    }
    I expect the output to be 'The value from isdigit: 0' for any non digit, and 'The value of isdigit: 1' for any digit. When it is a non digit entry I get 0 as I expected, but for a digit entry, I get 2048. Why is this so?

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    The values returned are nonzero if the character c falls
    into the tested class, and a zero value if not.

  3. #3
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    Ah, I thought this was the case, but I wanted to be sure. Thanks Thantos

    ~/

  4. #4
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    you don't need the fflush(stdout); because you have the \n in the printf string, which automatically flushes the buffer right?(C Gurus correct me if I am wrong)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. isdigit function
    By jdavenport in forum C Programming
    Replies: 5
    Last Post: 11-18-2005, 09:26 PM
  2. isdigit woes
    By kryonik in forum C Programming
    Replies: 3
    Last Post: 10-14-2005, 05:10 PM
  3. I read the FAQ on isdigit() but...
    By CaptainJack in forum C Programming
    Replies: 5
    Last Post: 03-16-2004, 06:03 AM
  4. #include cctype and the isdigit
    By nextus in forum C++ Programming
    Replies: 2
    Last Post: 12-26-2002, 07:55 PM
  5. Correct use of isdigit
    By DocDroopy in forum C Programming
    Replies: 3
    Last Post: 08-05-2002, 07:22 AM