title: Checking for balanced parentheses in C
body: <p>so the program should open a .c file and check for balanced parentheses, however my program keeps crashing. I think the problem maybe in the <code>while</code> loop to check for every character in the file. </p>
  
  <pre><code>typedef struct nodo {
      char llave;        
      struct nodo *sig;  
  } nodo;
  
  void push(struct nodo **top, int nuevo_dato);
  int pop(struct nodo **top);
  
  bool match(char signo1, char signo2);
  bool check(FILE *fp);
  
  int main() {    
      int k;
  
      printf("Seleccionar Opción\n1.Analizar 1\n2.Analizar 2\n3.Analizar 3\n4.Analizar 4\n5.Salir");
      scanf("%d", &amp;k);
  
      do {
          switch (k) {
          case 1: ;
              FILE *f1;                    
              f1 = fopen("1.c", "r");
              if (check(f1))
                  printf("Damn");
              fclose(f1);
              break;
          case 2: ;
              FILE *f2;
              f2 = fopen("2.c", "r");
          case 3: ;
              FILE *f3;
              f3 = fopen("3.c", "r");
          case 4: ;
              FILE *f4;
              f4 = fopen("4.c", "r");            
          }    
      } while (k!=5);
  }
  
  bool check(FILE *fp) {
      int j, i = 0;
      char *signo;
      nodo *stack = NULL;
      signo = malloc(100000);
      while (signo = fgetc(fp) != EOF {
  
          if (signo[i] == '{' || signo[i] == '(' || signo[i] == '[') 
              push(&amp;stack, signo[i]);
  
          if (signo[i] == '}' || signo[i] == ')' || signo[i] == ']') {
              if (stack == NULL) {
                  return false; 
              }
              else if (!match(pop(&amp;stack), signo[i])) {
                  return false;
              }
          }
          i++;
      }
  }
  
  bool match(char signo1, char signo2) {
      if (signo1 == '(' &amp;&amp; signo2 == ')')
          return true;
      else if (signo1 == '{' &amp;&amp; signo2 == '}')
          return true;
      else if (signo1 == '[' &amp;&amp; signo2 == ']')
          return true;
      else
          return false;
  }
  
  void push(struct nodo **top, int nueva_llave) {
      nodo *nuevo_nodo = (struct nodo*)malloc(sizeof(nodo));
  
      if (nuevo_nodo == NULL) {
          printf("Stack overflow \n");
      }           
  
      /* put in the data  */
      nuevo_nodo-&gt;llave  = nueva_llave;
  
      /* link the old list off the new node */
      nuevo_nodo-&gt;sig = (*top);  
  
      /* move the head to point to the new node */
      (*top) = nuevo_nodo;
  }
  
  /* Function to pop an item from stack*/
  int pop(struct nodo **top_ref) {
      char res;
      struct nodo *top;
  
      /*If stack is empty then error */
      if (*top_ref == NULL) {
          printf("Stack overflow \n");
      } else {
          top = *top_ref;
          res = top-&gt;llave;
          *top_ref = top-&gt;sig;
          free(top);
          return res;
      }
  }
  </code></pre>