//编写一个程序,它从标准输入读取C源代码,并验证所有的花括号都正确的成对出现
#include<stdio.h>
int main()
{
int ch=0;
int count=0;
while((ch=getchar())!=EOF)
{
if(ch==‘{‘)
count++;
else if((ch==‘}‘)&&(count==0))
{
printf("匹配不成功!\n");
}
else if((ch==‘}‘)&&(count!=0))
count--;
}
if(count==0)
printf("匹配成功!\n");
else
printf("匹配不成功!\n");
system("pause");
return 0;
}运行结果如下:
原文:http://760470897.blog.51cto.com/10696844/1705290