| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 828 人关注过本帖
标题:[求助]怎么区分算式中的符号和数字?
只看楼主 加入收藏
li331823679
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-8-3
收藏
 问题点数:0 回复次数:6 
[求助]怎么区分算式中的符号和数字?

输入一个四则混合运算的算式,怎么把算式中的数字和符号区分开?
谢谢大侠们!!

搜索更多相关主题的帖子: 算式中 符号 数字 
2006-08-03 20:02
OmO
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2006-7-28
收藏
得分:0 
利用ASCII代码值判断大小就可以了

2006-08-03 21:10
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
if(c>='0'&&c<='9')/*数字*/

if(c=='+')/*运算符*/
if(c=='-')
if(c=='*')
if(c=='/')

倚天照海花无数,流水高山心自知。
2006-08-04 14:12
OmO
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2006-7-28
收藏
得分:0 
好像ANSI C标准里的ctype.h的函数可以判断数字和符号

2006-08-04 15:05
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
判断是否是数字:int isdigit(int ch);
头文件是ctype.h
其他的判断只有一个一个来了。

倚天照海花无数,流水高山心自知。
2006-08-04 15:23
OmO
Rank: 1
等 级:新手上路
帖 子:69
专家分:0
注 册:2006-7-28
收藏
得分:0 
ctype.h

@函数名称: isalpha
函数原型: int isalpha(int ch);
函数功能: 检查ch是否是字母.
函数返回: 1是字母返回 ,否则返回 0.
参数说明:
所属文件 &lt;ctype.h&gt;

#include &lt;stdio.h&gt;
#include &lt;ctype.h&gt;

int main()
{
char ch1='*';
char ch2='a';
if(isalnum(ch1)!=0)
printf("%c is the ASCII number or alphebet\n",ch1);
else
printf("%c is not the ASCII number nor alphebet\n",ch1);
if(isalnum(ch2)!=0)
printf("%c is the ASCII number or alphebet\n",ch2);
else
printf("%c is not the ASCII number nor alphebet\n",ch2);
return 0;
}


@函数名称: iscntrl
函数原型: int iscntrl(int ch);
函数功能: 检查ch是否控制字符(其ASCII码在0和0x1F之间,数值为 0-31).
函数返回: 是返回 1,否则返回 0.
参数说明:
所属文件: &lt;ctype.h&gt;

#include &lt;stdio.h&gt;
#include &lt;ctype.h&gt;

char chars[]={'A',0x09,'Z'};
#define SIZE sizeof(chars)/sizeof(char)

int main()
{
int i;
for(i=0;i&lt;SIZE;i++){
printf("Char %c is %sa Control character\n",
chars,(iscntrl(chars))?"":"not");
}
return 0;
}


@函数名称: isdigit
函数原型: int isdigit(int ch);
函数功能: 检查ch是否是数字(0-9)
函数返回: 是返回1,否则返回0
参数说明:
所属文件: &lt;ctype.h&gt;

#include &lt;stdio.h&gt;
#include &lt;ctype.h&gt;

int main()
{
char ch1='1';
char ch2='a';
if(isdigit(ch1)!=0)
printf("%c is the ASCII number\n",ch1);
else
printf("%c is not the ASCII number\n",ch1);
if(isdigit(ch2)!=0)
printf("%c is the ASCII number\n",ch2);
else
printf("%c is not the ASCII number\n",ch2);
return 0;
}


@函数名称: isgraph
函数原型: int isgraph(int ch);
函数功能: 检查ch是否可显示字符(其ASCII码在ox21到ox7E之间),不包括空格
函数返回: 是返回1,否则返回0
参数说明:
所属文件: &lt;ctype.h&gt;

#include &lt;stdio.h&gt;
#include &lt;ctype.h&gt;

int main()
{
char ch1=' ';
char ch2='a';
if(isgraph(ch1)!=0)
printf("%c is the ASCII printable character\n",ch1);
else
printf("%c is not the ASCII printable character\n",ch1);
if(isgraph(ch2)!=0)
printf("%c is the ASCII printable character\n",ch2);
else
printf("%c is not the ASCII printable character\n",ch2);
return 0;
}

@函数名称: islower
函数原型: int islower(int ch);
函数功能: 检查ch是否小写字母(a-z)
函数返回: 是返回1,否则返回0
参数说明:
所属文件: &lt;ctype.h&gt;
#include &lt;stdio.h&gt;
#include &lt;ctype.h&gt;

char chars[]={'A','a','z','Z'};

#define SIZE sizeof(chars)/sizeof(char)

int main()
{
int i;

for(i=0;i&lt;SIZE;i++){
printf("Char %c is %sa lowercase character\n",chars,(islower(chars))?"":"not");
}
return 0;
}


@函数名称: tolower
函数原型: int tolower(int ch);
函数功能: 将ch字符转换为小写字母
函数返回: 返回ch所代表的字符的小写字母
参数说明:
所属文件: &lt;ctype.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;ctype.h&gt;

int main()
{
char x='a', y='b',z='A',w='*';
printf("Character %c to lower is %c\n",x,tolower(x));
printf("Character %c to lower is %c\n",y,tolower(y));
printf("Character %c to lower is %c\n",z,tolower(z));
printf("Character %c to lower is %c\n",w,tolower(w));
return 0;
}


@函数名称: toupper
函数原型: int toupper(int ch);
函数功能: 将ch字符转换成大写字母
函数返回: 与ch相应的大写字母
参数说明:
所属文件: &lt;ctype.h&gt;
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;ctype.h&gt;

int main()
{
char x='a', y='b',z='A',w='*';
printf("Character %c to upper is %c\n",x,toupper(x));
printf("Character %c to upper is %c\n",y,toupper(y));
printf("Character %c to upper is %c\n",z,toupper(z));
printf("Character %c to upper is %c\n",w,toupper(w));
return 0;
}


@函数名称: isalnum
函数原型: int isalnum(int ch);
函数功能: 检查ch是否是字母或数字
函数返回: 是字母或数字返回1,否则返回0
参数说明:
所属文件: &lt;ctype.h&gt;
#include &lt;stdio.h&gt;
#include &lt;ctype.h&gt;

int main()
{
char ch1 ='*';
char ch2 ='a';
if(isalnum(ch1)!=0)
printf("%c is the ASCII number or alphebet\n",ch1);
else
printf("%c is not the ASCII number nor alphebet\n",ch1);
if(isalnum(ch2)!=0)
printf("%c is the ASCII number or alphebet\n",ch2);
else
printf("%c is not the ASCII number nor alphebet\n",ch2);
return 0;
}

@函数名称: isprint
函数原型: int isprint(int ch);
函数功能: 检查ch是否是可打印字符(包括空格),其ASCII码在ox20到ox7E之间
函数返回: 是返回1,否则返回0
参数说明:
所属文件: &lt;ctype.h&gt;
#include &lt;stdio.h&gt;
#include &lt;ctype.h&gt;

int main()
{
char ch1='\n';
char ch2='a';
if(isprint(ch1)!=0)
printf("%c is the ASCII printable charcater\n",ch1);
else
printf("%c is not the ASCII printable charcater\n",ch1);
if(isprint(ch2)!=0)
printf("%c is the ASCII printable charcater\n",ch2);
else
printf("%c is not the ASCII printable charcater\n",ch2);
return 0;
}


@函数名称: ispunct
函数原型: int ispunct(int ch);
函数功能: 检查ch是否是标点字符(不包括空格),即除字母,数字和空格以外的所有可打印字符
函数返回: 是返回1,否则返回0
参数说明:
所属文件: &lt;ctype.h&gt;
#include &lt;stdio.h&gt;
#include &lt;ctype.h&gt;

int main()
{
char ch1=',';
char ch2='a';
if(ispunct(ch1)!=0)
printf("%c is the ASCII punct\n",ch1);
else
printf("%c is not the ASCII punct\n",ch1);
if(ispunct(ch2)!=0)
printf("%c is the ASCII punct\n",ch2);
else
printf("%c is not the ASCII punct\n",ch2);
return 0;
}

@函数名称: isspace
函数原型: int isspace(int ch);
函数功能: 检查ch是否是空格符和跳格符(控制字符)或换行符
函数返回: 是返回1,否则返回0
参数说明:
所属文件: &lt;ctype.h&gt;
#include &lt;stdio.h&gt;
#include &lt;ctype.h&gt;

int main()
{
char ch1=' ';
char ch2='a';
if(isspace(ch1)!=0)
printf("%c is the space charcater\n",ch1);
else
printf("%c is not the space charcater\n",ch1);
if(isspace(ch2)!=0)
printf("%c is the space charcater\n",ch2);
else
printf("%c is not the space charcater\n",ch2);
return 0;
}


@函数名称: isupper
函数原型: int isupper(int ch);
函数功能: 检查ch是否是大写字母(A-Z)
函数返回: 是返回1,否则返回0
参数说明:
所属文件: &lt;ctype.h&gt;

#include &lt;stdio.h&gt;
#include &lt;ctype.h&gt;

char chars[]={'A','a','z','Z'};

#define SIZE sizeof(chars)/sizeof(char)

int main()
{
int i;
for(i=0;i&lt;SIZE;i++){
printf("Char %c is %san uppercase character\n",
chars,(isupper(chars))?"":"not");
}
return 0;
}


@函数名称: isxdigit
函数原型: int isxdigit(int ch);
函数功能: 检查ch是否是一个16进制数学字符(即0-9,或A-F,或a-f)
函数返回: 是返回 1,否则返回0
参数说明:
所属文件: &lt;ctype.h&gt;
#include &lt;stdio.h&gt;
#include &lt;ctype.h&gt;

int main()
{
char ch1='1';
char ch2='a';
if(isxdigit(ch1)!=0)
printf("%c is the ASCII hexadecimal number\n",ch1);
else
printf("%c is not the ASCII hexadecimal number\n",ch1);
if(isxdigit(ch2)!=0)
printf("%c is the ASCII hexadecimal number\n",ch2);
else
printf("%c is not the ASCII hexadecimal number\n",ch2);
return 0;
}


@函数名称: isascii
函数原型: int isascii(int ch)
函数功能: 测试参数是否是ASCII码0-127
函数返回: 非零-是,0-不是
参数说明: ch-被测参数
所属文件: &lt;ctype.h&gt;

#include &lt;stdio.h&gt;
#include &lt;ctype.h&gt;

char chars[]={'A',0x80,'Z'};

#define SIZE sizeof(chars)/sizeof(char)

int main()
{
int i;
for(i=0;i&lt;SIZE;i++)
{
printf("Char %c is %san ASCII character\n",
chars,(isascii(chars))?"":"not");
}
return 0;
}


2006-08-04 20:36
li331823679
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-8-3
收藏
得分:0 

谢谢啊!
知道了些!!

2006-08-04 22:12
快速回复:[求助]怎么区分算式中的符号和数字?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018127 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved