#include<stdio.h>
main()
{
 FILE *stream;
 char ch;
 int ERROR,A[3];
 char *MESSAGE[]={
      "There is (\nYou can't open[",
      "There is [\nYou can't open{",
      "There isn't (\nYou can't close it",
      "There is( or there isn't[\nYou can't close]",
      "There is( or [ or there isn't {\nYou can't close}",
      "There are more brakets"};
 ERROR=-1;
 stream=fopen("data.txt","rt");
 A[0]=0;A[1]=0;A[2]=0;
 while( ((ch=fgetc(stream))!=EOF)&&(ERROR==-1) )
  {switch (ch)
   {
    case'(' : A[0]++;break;
    case'[' : if (A[0]!=0) {ERROR=0;break;};  A[1]++;break;
    case'{' : if ((A[0]!=0)||(A[1]!=0)) {ERROR=1;break;}   A[2]++;break;
    case')' : if(A[0]==0){ERROR=2;break;}  A[0]--;break;
    case']' : if((A[0]>0)||(A[1]==0)) {ERROR=3;break;}  A[1]--;break;
    case'} ': if((A[0]>0)||(A[1]>0)||(A[2]==0)) {ERROR=4;break}  A[2]--;
	      break;}
   }
  if((ERROR==-1) && ((A[0]>0)||(A[1]>0)||(A[2]>0)))
    ERROR=5;
  if((ERROR==-1)
    printf("\nNo error");
  else
   {
    printf("\nThere is an error!N%d\n",ERROR);
    while(*MESSAGE[ERROR]++!='\0')
     printf("%d",*MESSAGE[ERROR]);
   }
   return 0;
}

