如何判断它是英文字母还是数字? [英] How to decide whether it is an English letter or a number?
问题描述
例如,我从输入中读取了一个字母
我需要判断它是字母还是数字
我正在做的是
char a;
...... //读一个
int true = false;
if(( (a> =''0'')&&(a< =''9''))| |((a> =''a'')&&(a< = ''z''))||((a> =''A'')
&&(a< =''Z'')))
true = 1;
有没有更简单的方法呢?
非常感谢!
QQ写道:
例如,我从输入中读取了一个字符
我需要决定是否这是一封信或一个数字
我在做什么是
char a;
..... //读一个
int true = false;
if (((a> =''0'')&&(a< ='''9''))| |((a> =''a'')&&(a< ; ='''z''))||((a> =''A'')
& &(a< =''Z'')))
true = 1;
有没有更简单的方法呢?
非常感谢!
< hint>
尝试查看ctypes.h。
< / hint>
-
删除你的外套 to tontact me。
" QQ" <菊**** @ yahoo.com>在消息中写道
news:11 ********************** @ f6g2000cwb.googlegro ups.com ...例如,我从输入中读取了一个字母
我需要判断它是一个字母还是一个数字
我在做什么是
char a;
..... //读取
int true = false;
if(((> =''0'')&&(a< =''9' '))| |((a> ='''')&&(a< =''z''))||((a> =''A'')
&&(a< =''Z'')))
true = 1;
有没有更简单的方法呢?
非常感谢!
isdigit(),isalpha()等。
-
Fred L. Kleinschmidt
波音助理技术研究员
技术架构师,软件重用项目
Dale写道:QQ写道:
例如,我从输入中读取了一个字符
我需要决定是否是一个字母或数字
< hint>
尝试查看ctypes.h。
< / hint>
如果这不起作用,请尝试< ctype.h> 。
另外,请仔细阅读文档:这些函数接受
范围为[0,UCHAR_MAX]的值;如果你有一些简单的
或签名的字符,那么你必须在传递之前将它们转换为unsigned char
。
for instance, I read a char from the input
and I need to decide whether it is a letter or a number
What I am doing is
char a;
...... // read a
int true = false;
if(( (a >=''0'') && (a <=''9'')) | | ((a >=''a'') && (a <= ''z'')) ||((a >=''A'')
&& (a <= ''Z'')))
true = 1;
Is there any easier way for it?
Thanks a lot!
QQ wrote:
for instance, I read a char from the input
and I need to decide whether it is a letter or a number
What I am doing is
char a;
..... // read a
int true = false;
if(( (a >=''0'') && (a <=''9'')) | | ((a >=''a'') && (a <= ''z'')) ||((a >=''A'')
&& (a <= ''Z'')))
true = 1;
Is there any easier way for it?
Thanks a lot!
<hint>
Try looking in ctypes.h.
</hint>
--
Remove "your coat" to tontact me.
"QQ" <ju****@yahoo.com> wrote in message
news:11**********************@f6g2000cwb.googlegro ups.com...for instance, I read a char from the input
and I need to decide whether it is a letter or a number
What I am doing is
char a;
..... // read a
int true = false;
if(( (a >=''0'') && (a <=''9'')) | | ((a >=''a'') && (a <= ''z'')) ||((a >=''A'')
&& (a <= ''Z'')))
true = 1;
Is there any easier way for it?
Thanks a lot!
isdigit(), isalpha(), etc.
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project
Dale wrote:QQ wrote:for instance, I read a char from the input
and I need to decide whether it is a letter or a number
<hint>
Try looking in ctypes.h.
</hint>
If that doesn''t work, try <ctype.h> .
Also, read the documentation carefully: those functions accept
a value in the range [0, UCHAR_MAX]; if you have some plain
or signed chars then you have to cast them to unsigned char
before passing them.
这篇关于如何判断它是英文字母还是数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!