我的问题就是 输入数据到数组之后 无法进行下一步 找不到问题在哪
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
int match(char* str)
{
char stackMemroy[1024];
int top = -1;
int i = 0;
while (str[i] != '\0')
{
if (str[i] == ')')
{
if (top > -1)
{
top --;
}
else
{
return -1;
}
}
else if (str[i] == '(')
{
stackMemroy[++top] = str[i];
}
i++;
}
if (top == -1)
return 0;
else
return 1;
}
int main()
{
while (1)
{
char str[1024] = "";
/*get_s(str, 1024);*/
scanf_s("%s",str);
int result = match(str);
if (result == 0)
{
printf("匹配\n");
}
else if (result == 1)
{
printf("多了左边括号\n");
}
else
{
printf("多了右边括号\n");
}
}
return 0;
}
你这个传参是不是有问题,str是数组,但是你函数里面只是个char,而且函数里面是个指针变量,你传的参数应该个指针吧{我不是很确定,好久之前学的C,现在搞Java,但是感觉可能是这两方面有问题,你可以试着改改看}