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;
}
-1
A
回答
4
如果你想在你的代码中使用缩进,你可以发现问题容易得多:
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教程”获取更多信息。
0
我使用的技巧是通过输入,保留括号的计数器。对于每个'(',递增计数器,对于每个')',递减计数器并检查其是否定的(以发现具有相同数量的左侧和右侧支配的“())(()”的东西,但是不平衡)。如果计数器在任何时候都变为负值,那么这些参数是不平衡的,否则,如果计数器在最后为零,它们会保持平衡。老实说,我完全不明白你想用上面的代码来完成什么,而且我在阅读学生C代码方面有很多经验,所以我可以给你的只是算法建议。
相关问题
- 1. 我的错误在这个查询中,我认为这是正确的,但它标记了一个错误
- 2. 查找不平衡括号和括号
- 3. 如何纠正'System.Runtime.InteropServices.COMException'的这个错误?
- 4. ASP.NET MVC - 我认为我正在讨论这个错误
- 5. 基本递归,检查平衡括号
- 6. 我是这样做的,但我无法摆脱错误
- 7. 运行时错误的平衡括号
- 8. 我认为这是一个错误代码,可可编程
- 9. 为什么我得到这个错误,我该如何纠正它?
- 10. 如何纠正这个错误..?
- 11. 我该如何纠正这个facebook错误?
- 12. 平衡括号
- 13. Python re.compile。不平衡括号错误
- 14. 我如何纠正这个警告?
- 15. 我为SQL Server的这个子查询做了什么错误?
- 16. 括号平衡器程序
- 17. 我需要做些什么来纠正这个SQL语句?
- 18. 我应该如何纠正这个指针问题,它给我一个错误
- 19. 这是使用Dapper的正确方式还是我做错了?
- 20. 我试图纠正这一Django的对象设置错误,但它未能
- 21. 这是线程代码做我认为是什么?
- 22. 我如何纠正这个正则表达式模式为PHP
- 23. 这是一个PHP preg_match错误还是我做错了什么?
- 24. 我的MySQLi查询给出了错误,但我找不到这是错误的
- 25. 如何纠正函数式编程中的这个错误?
- 26. 我在做这个递归还是会被认为是迭代?
- 27. python正则表达式不平衡括号错误
- 28. Python正则表达式错误:不平衡括号
- 29. Bash-当我试图得到16的平方,这是错误的
- 30. 在这种情况下,我如何平衡“Pythonic”和“方便”?
它有什么不对?它会产生错误的结果吗? – MJB 2010-04-16 16:03:20
输入缓冲区相当小。您可能希望使其变大或添加大小检查以防止缓冲区溢出。 – futureelite7 2010-04-16 16:04:39
这会编译吗?如果您需要在“if”块中包含多行代码,则需要使用{}将它们包围。 – Vicky 2010-04-16 16:12:53