标签:scanf 表达 ring log strcpy nbsp class sha bsp
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
char s[10];
int x=0;
void A();
void B();
void C();
void D();
void E();
int main()
{
int len;
printf("请输入算术表达式:(以#为结束)\n");
scanf("%s",s);
len=strlen(s);
s[len]=‘#‘;
s[len+1]=‘\0‘;
A();
printf("True!\n");
strcpy(s,"");
x=0;
return 0;
}
void A()
{
C();
B();
}
void B()
{
if(s[x]==‘+‘||s[x]==‘-‘)
{
x++;
C();
B();
}
}
void C()
{
E();
D();
}
void D()
{
if(s[x]==‘*‘||s[x]==‘/‘)
{
x++;
E();
D();
}
}
void E()
{
if(s[x]>=‘a‘&&s[x]<=‘z‘)
{
x++;
}
else if(s[x]>=0&&s[x]<=9)
{
x++;
}
else if (s[x]==‘(‘)
{
x++;
A();
if(s[x]==‘)‘)
{
x++;
}
else
{
printf("Error!\n");
exit(0);
}
}
else
{
printf("Error!\n");
exit(0);
}
}
标签:scanf 表达 ring log strcpy nbsp class sha bsp
原文地址:http://www.cnblogs.com/170he/p/6193259.html