If Else statements

This is a discussion on If Else statements within the C++ Programming forums, part of the General Programming Boards category; I don't know how to include lower case a-z or upper case A-Z in a if else statements thanks in ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    2

    If Else statements

    I don't know how to include lower case a-z or upper case A-Z in a if else statements

    thanks in advance.

    If oneChar between 'a' ... 'z' or 'A' ... 'Z', then returns
    // true, else, returns false.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,604
    Take a look at some C string/character functions.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Information Crocodile
    Join Date
    Dec 2004
    Posts
    204
    ascii value of A-Z is 65 to 90
    and a-z is 97 to 122

    sample:
    Code:
    char b = 'b';
    
    if( b <= 65 && b >= 90 )
       return true;

  4. #4
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by rdave1
    I don't know how to include lower case a-z or upper case A-Z in a if else statements

    thanks in advance.

    If oneChar between 'a' ... 'z' or 'A' ... 'Z', then returns
    // true, else, returns false.
    Code:
    bool is_a_to_z( char c ) {
       return (( c >= 'a' && c <='z' ) || ( c >= 'A' && c <='Z' ) );
    }
    and use it like this
    Code:
       char c;
       cin >> c;
       if ( ! is_a_to_z(c) ) {
            cout << "illegal chracter '" << c << "'" << endl;
       }
    is that what you are looking for ?
    Kurt
    Last edited by ZuK; 09-15-2005 at 09:43 AM.

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Of course you all are assuming ASCII wish isn't required. Since it appears that you want to know if its an alphabetic character why not just use isalpha()?

  6. #6
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by Thantos
    Of course you all are assuming ASCII wish isn't required. Since it appears that you want to know if its an alphabetic character why not just use isalpha()?
    And you are assuming english char-set. In other char-sets there are more char's for witch isalpha() would return true.
    On the other hand there are few questions on this board that can be answered without any assumptions.
    Kurt

  7. #7
    Information Crocodile
    Join Date
    Dec 2004
    Posts
    204
    Quote Originally Posted by Thantos
    Of course you all are assuming ASCII wish isn't required. Since it appears that you want to know if its an alphabetic character why not just use isalpha()?
    Quote Originally Posted by ZuK
    And you are assuming english char-set. In other char-sets there are more char's for witch isalpha() would return true.
    On the other hand there are few questions on this board that can be answered without any assumptions.
    Kurt
    indeed indeed

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 03:09 AM
  2. newbie question - if statements without conditions
    By c_h in forum C++ Programming
    Replies: 2
    Last Post: 07-18-2008, 10:42 AM
  3. C++ If Statements Help
    By moporho in forum C++ Programming
    Replies: 19
    Last Post: 01-18-2008, 07:40 AM
  4. Efficiency of case statements
    By Yasir_Malik in forum C Programming
    Replies: 26
    Last Post: 05-23-2006, 11:36 AM
  5. Need help with "if" statements
    By Harryt123 in forum C Programming
    Replies: 22
    Last Post: 05-14-2006, 08:18 AM

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