输入一个字符,判断中文 数字 字母该字符是字母,数字,空格还是其他字符

来 自:盐城
等 级:侠之大者
帖 子:176
专家分:454
#include &stdio.h&
void main()
&&& scanf(&%c&,&dj);
&&& if(dj&='A'&&dj&='z') printf(&%c is char&,dj);
&&& if(dj&='0'&&dj&='9') printf(&%c is number&,dj);
&&& if(dj==' ') printf(&%c is blank&,dj);
&&& else printf(&other&);
我也是新手,程序写的没什么水平,见谅啊
等 级:新手上路
没事的,只是dj是什么意思,没学过呀!
等 级:新手上路
不应该是int main ()吗?还有怎么判断是控制字符?
等 级:论坛游民
专家分:15
使用ctype.h里的函数啊
等 级:蝙蝠侠
帖 子:346
专家分:953
回复 3楼 周园园
……你还是好好看书去吧,连dj是什么都不知道,dj就是Disc jockey
等 级:新手上路
帖 子:19
运用ascii码
等 级:新手上路
回复 6楼 shmilyflf
我们才开始学c语言,书上没有此类例题,也没学过dj,有没有别的方法?
来 自:太平洋
等 级:职业侠客
帖 子:220
专家分:310
刚学这个就别写吧,这就是个选择结构的题,看看ASCII就行了,应该在书末有吧。
从来都是无所谓,现在也该学着有所谓。✿咱们一个人,别坐井观天❀
等 级:论坛游民
帖 子:43
专家分:55
楼上说的对
版权所有,并保留所有权利。
Powered by , Processed in 0.031417 second(s), 8 queries.
Copyright&, BCCN.NET, All Rights Reserved等 级:蜘蛛侠
帖 子:515
专家分:1366
从ASCII码入手,这就是思路
为游戏狂~~!!&&& 大家努力编哈!
等 级:青峰侠
帖 子:482
专家分:1599
程序代码:#include&stdio.h&
int main(void)
&&& //输入一行字符,分别统计出其中英文字母、空格、数字和其他字符的个数。
&&& int char_num=<font color=#,kongge_num=<font color=#,int_num=<font color=#,other_num=<font color=#;
&&& while((ch=getchar())!='\n')//回车键结束输入,并且回车符不计入
&&&&&&&&if(ch&='a'&&ch&='z'||ch&='z'&&ch&='a')
&&&&&&&&&&&&char_num++;
&&&&&&&&else if(ch==' ')
&&&&&&&&&&&&kongge_num++;
&&&&&&&&else if(ch&='<font color=#'&&ch&='<font color=#')
&&&&&&&&&&&&int_num++;
&&&&&&&&else
&&&&&&&&&&&&other_num++;
&&& printf(&字母= %d,空格= %d,数字= %d,其它= %d\n&,char_num,kongge_num,int_num,other_num);
&&& return <font color=#;
等 级:业余侠客
帖 子:59
专家分:215
楼上的这个很好啊
#include&stdio.h&
&&& int char_num=0,kongge_num=0,int_num=0,other_num=0;
&&& while((ch=getchar())!='\n')&&& {
&&&&&&&&if(ch&='a'&&ch&='z'||ch&='z'&&ch&='a')
&&&&&&&&&&&&char_num++;
&&&&&&&&else if(ch==' ')
&&&&&&&&&&&&kongge_num++;
&&&&&&&&else if(ch&='0'&&ch&='9')
&&&&&&&&&&&&int_num++;
&&&&&&&&else
&&&&&&&&&&&&other_num++;
&&& printf(&字母= %d,空格= %d,数字= %d,其它= %d\n&,char_num,kongge_num,int_num,other_num);
&&& return 0;
等 级:新手上路
帖 子:97
同意三楼的
等 级:论坛游民
帖 子:19
专家分:28
以下是引用Y_Jo_1在 22:00:00的发言:
楼上的这个很好啊
&&& int char_num=0,kongge_num=0,int_num=0,other_num=0;
&&& while((ch=getchar())!='\n')&&& {
&&&&&&&&if(ch&='a'&&ch&='z'||ch&='z'&&ch&='a')
&&&&&&&&&&&&char_num++;
&&&&&&&&else if(ch==' ')
&&&&&&&&&&&&kongge_num++;
&&&&&&&&else if(ch&='0'&&ch&='9')
&&&&&&&&&&&&int_num++;
&&&&&&&&else
&&&&&&&&&&&&other_num++;
&&& printf(&字母= %d,空格= %d,数字= %d,其它= %d\n&,char_num,kongge_num,int_num,other_num);
&&& return 0;
来 自:中国
等 级:职业侠客
帖 子:179
专家分:323
等 级:职业侠客
帖 子:286
专家分:308
别急着结,我想想。。。。。。。。用别的方法。。。
最惨的不是忘不了悲伤的回忆,而是那些悲伤的回忆却开始记不清。。。
等 级:职业侠客
帖 子:286
专家分:308
程序代码:#include & stdio.h &
#include & stdlib.h &
#include & ctype.h &
void main ( )
&&& int sum1 = <font color=#;
&&& int sum2 = <font color=#;
&&& int sum3 = <font color=#;
&&& int sum4 = <font color=#;
&&& while((ch=getchar())!='\n')
&&&&&&&&if ( isdigit ( ch ) != <font color=# )
&&&&&&&&&&&&sum1++;
&&&&&&&&else if ( isspace ( ch ) != <font color=# )
&&&&&&&&&&&&sum2++;
&&&&&&&&else if ( islower ( ch ) != <font color=# || isupper ( ch ) != <font color=# )
&&&&&&&&&&&&sum3++;
&&&&&&&&else
&&&&&&&&&&&&sum4++;
&&& printf ( &<font color=#d%5d%5d%5d&, sum1, sum2, sum3, sum4 );
&&& system ( &pause& );
}果然我用函数做出来了,哈哈,为自己高兴。。。。。。。。。。。。
最惨的不是忘不了悲伤的回忆,而是那些悲伤的回忆却开始记不清。。。
等 级:版主
威 望:230
帖 子:19711
专家分:38082
回复 9楼 吴军旗
授人以渔,不授人以鱼。
版权所有,并保留所有权利。
Powered by , Processed in 0.027484 second(s), 8 queries.
Copyright&, BCCN.NET, All Rights Reserved考试遇到,直接没思路
会scanf字符串吗会读一行吗会遍历字符串吗会判断字符ASCII码值吗你不会,平时都干嘛去了?
字母数字空格好办,POSIX和M$都有相应的扩展函数可以判断字母数字;中文稍微麻烦,GBK还算简单读第一个字节如果不是字母数字空格就判断是否大于0x80小于0xFF,然后继续往后读一个字节看是否大于0x40,且不等于0x7F或者0xFF 必须同时满足这两个条件才算一个GBK的字符参考文献 写了一个例子,没认真写#include &stdio.h&
#include &string.h&
int main(int argc, char* argv[])
unsigned char Seq[256];
int nAlpha = 0, nNum = 0, nSpace = 0, nGBK = 0;
printf("Input a sequence:\n");
fgets(Seq, 256, stdin);
l = strlen(Seq);
for(i = 0; i & ++i)
if(isdigit(Seq[i]))
if(isalpha(Seq[i]))
if(Seq[i]==0x20)
if(Seq[i]&0xFF && Seq[i]&0x80)
if(Seq[i+1] & 0x40)
if(Seq[i+1]!=0x7F && Seq[i+1]!=0xFF)
printf("%d Alphabets, %d Numbers, %d Spaces, %d GBK 2-byte Characters in the sequence\n",
nAlpha, nNum, nSpace, nGBK);c语言作业4_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
评价文档:
喜欢此文档的还喜欢
c语言作业4
1&#8203;.&#8203;从&#8203;键&#8203;盘&#8203;上&#8203;输&#8203;入&#8203;一&#8203;个&#8203;字&#8203;符&#8203;,&#8203;用&#8203;i&#8203;f&#8203;结&#8203;构&#8203;编&#8203;程&#8203;判&#8203;断&#8203;该&#8203;字&#8203;符&#8203;是&#8203;英&#8203;文&#8203;字&#8203;符&#8203;、&#8203;数&#8203;字&#8203;字&#8203;符&#8203;、&#8203;空&#8203;格&#8203;符&#8203;还&#8203;是&#8203;其&#8203;他&#8203;字&#8203;符&#8203;。&#8203;
&#03;.&#8203;从&#8203;键&#8203;盘&#8203;输&#8203;入&#8203;三&#8203;角&#8203;形&#8203;的&#8203;三&#8203;边&#8203;,&#8203;判&#8203;断&#8203;是&#8203;否&#8203;构&#8203;成&#8203;三&#8203;角&#8203;形&#8203;。&#8203;若&#8203;能&#8203;,&#8203;则&#8203;输&#8203;出&#8203;该&#8203;三&#8203;角&#8203;形&#8203;的&#8203;面&#8203;积&#8203;及&#8203;其&#8203;类&#8203;型&#8203;(&#8203;等&#8203;边&#8203;、&#8203;等&#8203;腰&#8203;、&#8203;直&#8203;角&#8203;、&#8203;一&#8203;般&#8203;)&#8203;,&#8203;否&#8203;则&#8203;输&#8203;出&#8203;“&#8203;不&#8203;能&#8203;构&#8203;成&#8203;三&#8203;角&#8203;形&#8203;”&#8203;。&#8203;
&#03;、&#8203;实&#8203;验&#8203;指&#8203;导&#8203;书&#03;3&#8203;页&#8203;拓&#8203;展&#8203;性&#8203;实&#8203;验
阅读已结束,如果下载本文需要使用
想免费下载本文?
把文档贴到Blog、BBS或个人站等:
普通尺寸(450*500pix)
较大尺寸(630*500pix)
你可能喜欢

我要回帖

更多关于 c 判断字符是否为数字 的文章

 

随机推荐