I have an array of characters populated by cin, but im trying to find a way to check each character individually to make sure its only one of a set number of characters (a-z,A-Z,0-9,[space]).
The easiest way I thought this could be done is to check if the code of the character fell within a certain range. But not sure how to get it.
Alternatively if anyone knows any other ways of doing it, that would be great.
The easiest way is to use
isalpha(),isdigit()orisalnum():These are defined in
ctype.h: http://www.cplusplus.com/reference/clibrary/cctype/Otherwise you can also use comparisons:
This latter approach using comparisons will generalize to arbitrary ranges.