1. 编写一个程序,它从标准输入读取C源代码,并验证所有的花括号都正确的成对出现.
(我的代码)
#include <stdio.h>
#include <string.h>
int main()
{
int cout=0,num=0;
int i;
char ch;
char *p=&ch;
for(i=0;i<10;i++)
{
scanf("%c",&ch);
//gets(ch);
switch (*p)
{
case '{':cout++;break;
case '}':num++;break;
default:ch++;
}
}
if(cout==num)
printf("括号匹配\n");
else
printf("匹配失败\n");
return 0;
}