# Range of characters in C++

#### gringo

hi,
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?
THX

Related Introductory Physics Homework Help News on Phys.org

#### AKG

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?

#### e(ho0n3

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:
if (*var <= 'K' || *var >= 'A')
without problems.

### Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving