On Mar 18, 8:41 pm, Paavo Helde <nob...@ebi.eewrote:
kundas...@gmail.com wrote in news:a6a5021d-b4da-49a8-8016-8b63e90c9e32
@i29g2000prf.googlegroups.com:
how to do simple code for:
if(alphabet)
output ERROR
because char is int I cannot do like this:
if(sale >= 'a' && sale =< 'z')
Why not?
Because lower case characters are not guaranteed to be
contiguous. (Nor are they with EBCDIC.)
because if my sale is 98 it will output error because b is
98.
The if clause above does not output any error :-S
I want number, not character.
Sorry, can't really understand what you want. The char and int
types are both holding numbers in C++ and can be converted
easily into each other (if values fit). It depends on the
program if it interprets the values as numbers or as ASCII
character codes. The iostream facility generally interprets
chars as ASCII character codes and ints as numbers, if this is
your concern you should convert the numbers from one type to
another.
If the question is how to determine if a particular value is
alphabetic or not, there's always:
#include <locale>
if ( std::isalpha( character, std::locale() ) )
or,
#include <cctype >
if ( std::isalpha( static_cast< unsigned char >( character ) ) )
(The first should work for any value in a char
variable---if the type containing the value is not a char, you
need to cast it to one first. The second will work for any
value in the range [0...UCHAR_MAX], or EOF---if the value is in
a char value, you must cast it to unsigned_char first, to ensure
that no negative values occur.)
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orient�e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S�mard, 78210 St.-Cyr-l'�cole, France, +33 (0)1 30 23 00 34