您的位置:首页 > 编程语言

//4.编写一个程序,它从标准输入读取C源代码,并验证所有的花括号都正确的成对出现。

2018-04-11 22:09 375 查看
//4.编写一个程序,它从标准输入读取C源代码,并验证所有的花括号都正确的成对出现。
#include<stdio.h>

int main()
{
int ch;
int count = 0;
while ((ch =getchar())!= EOF)
{
if (ch == '{')
{
count++;
}
else if (ch == '}')//}{不匹配
{
if (0 == count)
{
printf("not match\n");
system("pause");
return 1;
}
count--;
}
else
{
}
}
if (0 == count)
{
printf("match\n");
}
if (0 != count)
{
printf("not match\n");
}
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐