#include
void getstr(char* p){
printf("input:\t");
scanf("%s", p);
return;
}
void main(){
char st[255];/*在程序中没有起多大作用*/
int top = 0;
char str[255];
char k;
int i=0;
int st_error=0;
getstr(str);
while ( (k=str[i]) != 0)
{
if (k == '(' ) st[top++] = k;/*top++;也一样,因为st这个栈空间没有起到存储的作用*/
if (k == ')' )
{
if (top == 0 )
{
st_error=1;
break;
}
else
top--;
}
i++;
}
if(st_error==0&&top==0) printf("匹配检查通过\n");
else
if(st_error==1) printf("缺少左括号!\n");
else
if(top>0) printf("缺少右括号!\n");
}