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

时间:2015-10-31 01:42:46   收藏:0   阅读:246
#include<stdio.h>
int main()
{
int cou=0;
char ch;
while((ch=getchar())!=‘\n‘)
{
if(ch==‘{‘)
cou++;
else if(ch==‘}‘)
{
if(cou==0)
printf("匹配不成功!");
cou--;
}
}
if(cou==0)
printf("匹配成功!");
else
printf("匹配不成功!");
return 0;
}


本文出自 “fun” 博客,请务必保留此出处http://10725723.blog.51cto.com/10715723/1708224

原文:http://10725723.blog.51cto.com/10715723/1708224

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!