• Support PF! Buy your school textbooks, materials and every day products via PF Here!

Range of characters in C++

  • Thread starter gringo
  • Start date
1
0
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
 

AKG

Science Advisor
Homework Helper
2,559
3
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?
 
1,356
0
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.
 

Related Threads for: Range of characters in C++

Replies
5
Views
9K
Replies
2
Views
1K
  • Posted
Replies
1
Views
878
Replies
3
Views
6K
  • Posted
Replies
15
Views
3K
Replies
5
Views
369
  • Posted
Replies
14
Views
558

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
Top