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;
}
本文介绍了一个简单的C语言程序,该程序通过读取标准输入的C源代码并验证所有花括号是否正确配对来确保代码的语法正确性。
&spm=1001.2101.3001.5002&articleId=42060103&d=1&t=3&u=a6c22ae59d9d4d53948d01747ce8a10a)
291

被折叠的 条评论
为什么被折叠?



