编写一个程序,它从标准输入读取C源代码,并验证所有的花括号都正确的成对出现。 (VS ctrl+z退出 回车即可)
int Is_judge_both()
{
char ch = 0;
int count = 0;
while((ch=getchar()) != EOF)
{
if(ch == '{')
{
count++;
}
if(count == 0 && ch == '}')
{
printf("不匹配.");
return 0;
}
if(ch == '}' && count != 0)
{
count--;
}
}
if(count == 0)
{
printf("匹配.");
return 1;
}
else
{
printf("不匹配.");
return 0;
}
}