1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Range of characters in C++

  1. Jun 28, 2005 #1
    i have a little problem i m not able to check if an input character is in a specified range of characters. i.e is this char between A and Z let s say.
    I tried to use the ascII but it didn t work out; no syntax errors at compile time but the error occurs at run time.
    this is the code i used:
    if(var<=75 && var >=65) //75 is letter K and 65 letter A
    and var is a char *.

    where is my problem?
  2. jcsd
  3. Jun 28, 2005 #2


    User Avatar
    Science Advisor
    Homework Helper

    var is a char*? The value of a char* is a pointer, so you're checking if a pointer is less than 75, which doesn't make sense. I can't remember, but you might want to check something like &var or var& or var* or something like that. Again, my memory might be off, but should you have two ampersands? What is the actual error you're getting?
  4. Jun 28, 2005 #3
    First of all, a char* is a 32-bit hex value that points to some region of memory. To get the first value pointed to by var, you can either use *var or var[0].

    If you want to compare single characters, you can use

    Code (Text):
    if (*var <= 'K' || *var >= 'A')
    without problems.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook