程序:从标准输入C源代码,验证所有的“{”和“}”都是成对出现的

来源:互联网 发布:雅思自学 知乎 编辑:程序博客网 时间:2024/06/16 04:27
#include<stdio.h>#include<stdlib.h>#include<conio.h>int main(){    int ch;    int braces=0;    while((ch=getchar())!=EOF)    {      if(ch=='{')      braces++;      if(ch=='}')       if(braces==0) printf("Extra closing brace!\n");       else          braces--;    }    if(braces>0)    printf("%d braces not matched",braces);    system("pause");    return 0;}
资料:http://baike.baidu.com/
0 0
原创粉丝点击