I was wondering if there was a way to test if a key the user pressed is a character.
I was wondering if there was a way to test if a key the user pressed is a character.
"Computers aren't intelligent, they only think they are."
**infected by Blizzarddog**
I am a signature virus. Please add me to your signature so that I may multiply
Do you mean as in letters a-z? Look into the isalpha() function
"Think not but that I know these things; or think
I know them not: not therefore am I short
Of knowing what I ought."
-John Milton, Paradise Regained (1671)
"Work hard and it might happen."
-XSquared
All characters are stored as integer codes(a char type is actually an int), so you can test what character was entered by comparing it to the integer codes for the characters you are interested in.
For instance, the characters a-z are stored as the integer codes 97-122(from an ASCII table). So, if you wanted to check whether the char entered was a lower case letter, you could do something like this:
Code:char letter; cin>>letter; if(letter >= 97 && letter <= 122) cout<<"Found a lower case letter.";
Last edited by 7stud; 12-14-2003 at 11:26 PM.
http://www.cppreference.com/ascii.html <= an ASCII chart... most likely your machine is using ASCII... but I would go with the isalpha(); function found in <cstring>... it's alot easier and better for readability
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT