gpt4 book ai didi

c - 我这样做是为了平衡方程的括号,但我认为这是错误的检查并纠正它

转载 作者:行者123 更新时间:2023-11-30 18:32:57 25 4
gpt4 key购买 nike

int main(){
char i,input[30],close,open;
for(i=0;i<='.';i++){
printf("enter equation");
scanf("%c",input[i]);
if(input[i]=='(')
input++;
input[i]=open;
else if(input[i]==')')
input[i]--;
input[i]=close;
else if(open[i]==close[i])
{
printf("parenthesis are balance");
}
else
printf("parenthesis are not balance");
}

getch();
return 0;
}

最佳答案

如果您在代码上使用缩进,您可以更容易地发现问题:

int main()
{
char i,input[30],close,open;
for(i=0;i<='.';i++) // why i <= '.'? maybe you mean int i and input[i] != '.'...
{
printf("enter equation");
scanf("%c",input[i]); // you need &input[i]. In fact, I think what you need is scanf("%s", input); but outside of this for loop...
if(input[i]=='(')
input++; // Do you mean input[i]++?
input[i]=open; // this isn't inside the if condition. Use brackets if you want it to be
else if(input[i]==')') // won't compile because there's no matching if
input[i]--;
input[i]=close; // not inside the else. Also, what is close and open? You don't initialize them
else if(open[i]==close[i]) // open and close are not arrays. You can't use them like this
{
printf("paranthesis are balance");
}
else
printf("paranthesis are not balance");
}

getch();
return 0;
}

有很多错误。我建议阅读教程。 This one , 例如。您可以通过“C 教程”Google 搜索更多内容

关于c - 我这样做是为了平衡方程的括号,但我认为这是错误的检查并纠正它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2654409/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com