C语言的一些简单小函数

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

#include<stdio.h>

#include<Windows.h>
#include<stdlib.h>
int main()
{
char ch;
int count = 0;
while ((ch = getchar()) != EOF)
{
if (ch == '{')
count++;
else if (ch == '}' && 0 != count)
{
count--;
}
else if (ch == '}' && 0 == count)
{
printf("不匹配\n");
return 0;
}
}
if (0 == count)
{
printf("匹配\n");
system("pause");
}

return 0;

}

猜你喜欢

转载自blog.csdn.net/weixin_40797414/article/details/81027615