#include <iostream>
#include<stdio.h>
using namespace std;
#define MAXN 10
char push(char * stack, int maxn, int* toppt, char x)//进栈函数
{
if (*toppt >= maxn)
return 1;
stack[*toppt] = x;
++(*toppt);
return 0;
}
char pop(char* stack, int* toppt, char * cp)//出栈函数
{
if (*toppt == 0)
return 1;
--(*toppt);
*cp = stack[*toppt];
return 0;
}
void out(char * stack, int toppt)//展示当前栈函数
{
int i;
for (i = toppt - 1; i >= 0; i--)
printf("%c", stack[i]);
printf("\n");
}
void main()
{
char x,s[MAXN];
int top = 0;
printf("请输入括号1:");
scanf_s("%c", &x, sizeof(x));
push(s, MAXN, &top, x);
printf("进栈成功");
out(s, top);
printf("请输入括号2:");
scanf_s("%c", &x, sizeof(x));
push(s, MAXN, &top, x);
if (s[top-1] == '(' && s[top] == ')')
printf("配对成功");
if ((s[top-1] == '(' && s[top] == ')' )|| s[top-1] == ')')
printf("错误!");
}
请问大佬们为什么第一次输数据入栈之后,直接就跳过了
printf("请输入括号2:");
scanf_s("%c", &x, sizeof(x));
push(s, MAXN, &top, x);
if (s[top-1] == '(' && s[top] == ')')
printf("配对成功");
if ((s[top-1] == '(' && s[top] == ')' )|| s[top-1] == ')')
printf("错误!");
转到“按任意键继续”了,没法第二次入栈了