Thread: Check if next character is a letter?

  1. #1
    Unregistered
    Guest

    Question Check if next character is a letter?

    Im designing a program in which i need to check if the next char taken from a line of input is a letter. How would i do this with just the standard functions?

  2. #2
    Unregistered
    Guest

    Talking

    char letter;
    cin >> letter;

    if( (letter >= 'A' || letter <='Z') || ( letter >= 'a' || letter <= 'z' ) )
    {
    //continue as planned
    }
    else
    {
    arrgggg!!! not a letter, abort abort!!!!!!
    }


    or there is a function isalpha( int ) in ctype.h ehich does the same thing

  3. #3
    Fingerstyle Guitarist taylorguitarman's Avatar
    Join Date
    Aug 2001
    Posts
    564
    Sorry unregistered, but your code will aways result in the if statement being true. Anything inputed is either greater 'A' or less than 'Z'. You needed an && instead of ||.

    Anyways, just use isalpha().
    If a tree falls in the forest, and no one is around to see it, do the other trees make fun of it?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. HELP!!!!emergency Problem~expert please help
    By unknowppl in forum C++ Programming
    Replies: 9
    Last Post: 08-21-2008, 06:41 PM
  2. HELP!!!!emergency ~expert please help
    By unknowppl in forum C Programming
    Replies: 1
    Last Post: 08-19-2008, 07:35 AM
  3. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  4. LoadFromFile() from a txt
    By Snoopy104 in forum C++ Programming
    Replies: 6
    Last Post: 03-14-2006, 10:05 AM
  5. Suggest another way or how can my code be improved
    By peterchen in forum C Programming
    Replies: 6
    Last Post: 01-23-2006, 04:37 PM