#include <stdio.h> #include <string.h> #include <dir.h> #include <conio.h> bool TestBrackets(char *filename) { FILE *fp = fopen(filename, "rt"); if(!fp) return false; int OpenParentesis = 0, OpenBracket = 0; while(!feof(fp)) { int ch = fgetc(fp); switch(ch) { case '(': OpenParentesis++; break; case ')': if(OpenParentesis) OpenParentesis--; else return false; break; case '{': OpenBracket++; break; case '}': if(OpenBracket) OpenBracket--; else return false; break; } } return (!OpenParentesis && !OpenBracket); } int main(int ArgC, char *ArgV[]) { char filename[MAXPATH]; if(ArgC < 2) { printf("Digite o nome do arquivo: "); gets(filename); } else strcpy(filename, ArgV[1]); if(strlen(filename)) printf("O arquivo %s%s possui chaves ou parenteses abertos", filename, TestBrackets(filename) ? " nao" : ""); getch(); return 0; }