//从键盘输入一个目录文件名;
//打印.c文件,判断大括号是否成对出现;
#include<stdio.h> int main() { FILE *Rfile = NULL; char *Pput=NULL; char name[100] = "0"; int count=5; char ch='0'; flag: printf("请输入你要读取的文件目录与名字(eg:c:\\windows\\test.c):\n"); scanf("%s",name); Rfile = fopen(name,"r"); if (Rfile == NULL) { printf("你要访问的文件不存在,请重新输入目录!\n"); goto flag; } else { while (ch != EOF) { ch = fgetc(Rfile); putchar(ch); } fclose(Rfile); Rfile = fopen(name, "r"); ch = '0'; while (ch!= EOF) { ch = fgetc(Rfile); if(ch=='{') count++; if (ch=='}') count--; } if ( 5 == count ) printf("\n花括号成对出现!"); else if (count > 5) printf("\n正或括号比反或括号多了 %d\n***************************************", count - 5); else printf("\n反花括号比正花括号多了 %d\n***************************************",5 - count); } return 0; }