Thread: Character types

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    13
    Rep Power
    0

    Question Character types


    Hi,
    I'm looking for some C equavilents to these java functions:

    Code:
    char c = someChar;
    boolean isWhitespace = Character.isWhitespace(c);
    boolean isDigit = Character.isDigit(c);
    boolean isLetter = Character.isLetter(c);
    boolean isLetterOrDigit = Character.isLetterOrDigit(c);
    or something like this (even better):
    Code:
    switch(GetType(c))
    {
       case WHITESPACE:
          break;
       case LETTER:
          break;
       //etc...
    }
    Are there any?

    Thanks in advance,
    Nille
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,158
    Rep Power
    2222
    Look in ctype.h :

    isalpha()
    isalnum()
    isdigit()
    islower()
    isupper()
    isspace()
    isxdigit()
    iscntrl()
    etc.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    21
    Rep Power
    0
    yep use ctype.h header file for that macros
    use this sample program

    #include<ctype.h>
    main()
    {
    int ch;

    while((ch=getch()) != 'q')
    {
    if(isalpha(ch))
    printf("Alphabet\n");
    if(isdigit(ch))
    printf("Number\n");
    }
    }
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    13
    Rep Power
    0
    Thanks both of you!

IMN logo majestic logo threadwatch logo seochat tools logo