title: Some time the prgram runs some time it crashes in C
body: <p>I made this program in c, but some time it works and run perfectly and sometimes it doesn't anyone can help me with it?</p>
  <p>The program is in Portuguese, sorry if this is a problem.</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  typedef struct
  {
      char nome[40];
      char tel[15];
      char email[40];
      char status[2];
      int tipo;
  } cadeiras;
  </code></pre>
  <p>This first function is the Menu</p>
  <pre><code>void menu()
  { // Menu inicial do programa.
      printf(&quot;MENU PRINCIPAL \n\n&quot;);
      printf(&quot;1 - Visualizar mapa do teatro\n&quot;);
      printf(&quot;2 - Comprar cadeira\n&quot;);
      printf(&quot;3 - Reservar cadeira\n&quot;);
      printf(&quot;4 - Consultar uma determinada cadeira da Sala\n&quot;);
      printf(&quot;5 - Total arrecado\n&quot;);
      printf(&quot;6 - Sair do Aplicativo\n&quot;);
      printf(&quot;Digite o numero de uma das opcoes acima: &quot;);
  }
  </code></pre>
  <p>This function changes a number in to a leter.</p>
  <pre><code>void letranumero(int numero) 
  {
      switch (numero)
      {
      case 0:
          printf(&quot;A&quot;);
          break;
      case 1:
          printf(&quot;B&quot;);
          break;
      case 2:
          printf(&quot;C&quot;);
          break;
      case 3:
          printf(&quot;D&quot;);
          break;
      case 4:
          printf(&quot;E&quot;);
          break;
      case 5:
          printf(&quot;F&quot;);
          break;
      case 6:
          printf(&quot;G&quot;);
          break;
      case 7:
          printf(&quot;H&quot;);
          break;
      case 8:
          printf(&quot;I&quot;);
          break;
      case 9:
          printf(&quot;J&quot;);
          break;
      case 10:
          printf(&quot;K&quot;);
          break;
      case 11:
          printf(&quot;L&quot;);
          break;
      case 12:
          printf(&quot;M&quot;);
          break;
      case 13:
          printf(&quot;N&quot;);
          break;
      case 14:
          printf(&quot;O&quot;);
          break;
      case 15:
          printf(&quot;P&quot;);
          break;
      case 16:
          printf(&quot;Q&quot;);
          break;
      case 17:
          printf(&quot;R&quot;);
          break;
      case 18:
          printf(&quot;S&quot;);
          break;
      case 19:
          printf(&quot;T&quot;);
          break;
      case 20:
          printf(&quot;U&quot;);
          break;
      case 21:
          printf(&quot;V&quot;);
          break;
      case 22:
          printf(&quot;W&quot;);
          break;
      case 23:
          printf(&quot;X&quot;);
          break;
      case 24:
          printf(&quot;Y&quot;);
          break;
      case 25:
          printf(&quot;Z&quot;);
          break;
      }
  }
  </code></pre>
  <p>This function is the opposite of the last one. It changes a letter in to number. </p>
  <pre><code>void numeroletra(char letra, int *n) // Transforma a letra de uma fileira digitada em um numero.
  {
      switch (letra)
      {
      case 'A':
          *n = 0;
          break;
      case 'B':
          *n = 1;
          break;
      case 'C':
          *n = 2;
          break;
      case 'D':
          *n = 3;
          break;
      case 'E':
          *n = 4;
          break;
      case 'F':
          *n = 5;
          break;
      case 'G':
          *n = 6;
          break;
      case 'H':
          *n = 7;
          break;
      case 'I':
          *n = 8;
          break;
      case 'J':
          *n = 9;
          break;
      case 'K':
          *n = 10;
          break;
      case 'L':
          *n = 11;
          break;
      case 'M':
          *n = 12;
          break;
      case 'N':
          *n = 13;
          break;
      case 'O':
          *n = 14;
          break;
      case 'P':
          *n = 15;
          break;
      case 'Q':
          *n = 16;
          break;
      case 'R':
          *n = 17;
          break;
      case 'S':
          *n = 18;
          break;
      case 'T':
          *n = 19;
          break;
      case 'U':
          *n = 20;
          break;
      case 'V':
          *n = 21;
          break;
      case 'W':
          *n = 22;
          break;
      case 'X':
          *n = 23;
          break;
      case 'Y':
          *n = 24;
          break;
      case 'Z':
          *n = 25;
          break;
      }
  }
  </code></pre>
  <p>This function is to make te matrix have zeros.</p>
  <pre><code>void zerar(cadeiras cadeira[21][29])
  {
      int i, j;
      for (i = 0; i &lt; 22; i++)
          for (j = 0; j &lt; 30; j++)
          {
              strcpy(cadeira[i][j].nome, &quot; &quot;);
              strcpy(cadeira[i][j].tel, &quot; &quot;);
              strcpy(cadeira[i][j].email, &quot; &quot;);
              strcpy(cadeira[i][j].status, &quot;L&quot;);
              cadeira[i][j].tipo = 0;
          }
  }
  </code></pre>
  <p>This is the main function. It's supose to be a ticket office of theater.</p>
  <pre><code>int main()
  {
      cadeiras cadeira[21][29];
      int i, j, op, controle;
      char aux;
      if (controle != 1)
      {
          zerar(cadeira);
          controle = 1;
      }
      printf(&quot;  ******* T E A T R O ******* \n&quot;);
      do
      {
          menu();
          scanf(&quot;%d&quot;, &amp;op);
          printf(&quot;\n&quot;);
  
          switch (op)
          {
          case 1:
              for (i = 0; i &lt; 22; i++)
              {
                  for (j = 0; j &lt; 15; j++)
                  {
                      letranumero(i);
                      printf(&quot;%d-&quot;, j + 1);
                      printf(&quot;%s &quot;, cadeira[i][j].status);
                  }
  
                  printf(&quot;        &quot;);
  
                  for (j = 15; j &lt; 30; j++)
                  {
                      letranumero(i);
                      printf(&quot;%d-&quot;, j + 1);
                      printf(&quot;%s &quot;, cadeira[i][j].status);
                  }
                  printf(&quot;\n&quot;);
              }
              break;
  
          case 2:
              printf(&quot;Digite fileira da cadeira que deseja comprar: &quot;);
              scanf(&quot; %c&quot;, &amp;aux);
              numeroletra(aux, &amp;i);
              printf(&quot;Digite coluna da cadeira que deseja comprar: &quot;);
              scanf(&quot;%d&quot;, &amp;j);
              j--;
              if (cadeira[i][j].status[0] == 'L')
              {
                  printf(&quot;Digite o nome do cliente: &quot;);
                  fgets(cadeira[i][j].nome, 40, stdin);
                  printf(&quot;Digite o telefone do cliente: &quot;);
                  fgets(cadeira[i][j].tel, 15, stdin);
                  printf(&quot;Digite o email do cliente: &quot;);
                  fgets(cadeira[i][j].email, 40, stdin);
                  printf(&quot;Digite 1 pra Meia e 2 para Inteira: &quot;);
                  scanf(&quot;%d&quot;, &amp;cadeira[i][j].tipo);
                  if (cadeira[i][j].tipo != 1 &amp;&amp; cadeira[i][j].tipo != 2)
                  {
                      do
                      {
                          printf(&quot;Tipo invalido, digite 1 pra Meia e 2 para Inteira: &quot;);
                          scanf(&quot;%d&quot;, &amp;cadeira[i][j].tipo);
                      } while (cadeira[i][j].tipo != 1 &amp;&amp; cadeira[i][j].tipo != 2);
                  }
  
                  strcpy(cadeira[i][j].status, &quot;O&quot;);
                  printf(&quot;Cadeira comprada com sucesso!\n&quot;);
              }
              else
              {
                  printf(&quot;Cadeira ja esta ocupada!\n&quot;);
              }
              break;
  
          case 3:
              printf(&quot;Digite fileira da cadeira que deseja reservar: &quot;);
              scanf(&quot; %c&quot;, &amp;aux);
              numeroletra(aux, &amp;i);
              printf(&quot;Digite coluna da cadeira que deseja reservar: &quot;);
              scanf(&quot;%d&quot;, &amp;j);
              j--;
              if (cadeira[i][j].status[0] == 'L')
              {
                  printf(&quot;Digite o nome do cliente: &quot;);
                  fgets(cadeira[i][j].nome, 40, stdin);
                  printf(&quot;Digite o telefone do cliente: &quot;);
                  fgets(cadeira[i][j].tel, 15, stdin);
                  printf(&quot;Digite o email do cliente: &quot;);
                  fgets(cadeira[i][j].email, 40, stdin);
                  printf(&quot;Digite 1 pra Meia e 2 para Inteira: &quot;);
                  scanf(&quot;%d&quot;, &amp;cadeira[i][j].tipo);
                  if (cadeira[i][j].tipo != 1 &amp;&amp; cadeira[i][j].tipo != 2)
                  {
                      do
                      {
                          printf(&quot;Tipo invalido, digite 1 pra Meia e 2 para Inteira: &quot;);
                          scanf(&quot;%d&quot;, &amp;cadeira[i][j].tipo);
                      } while (cadeira[i][j].tipo != 1 &amp;&amp; cadeira[i][j].tipo != 2);
                  }
  
                  strcpy(cadeira[i][j].status, &quot;R&quot;);
                  printf(&quot;Cadeira reservada com sucesso!\n&quot;);
              }
              else
              {
                  printf(&quot;Cadeira ja esta ocupada!\n&quot;);
              }
              break;
          }
  
          printf(&quot;\n&quot;);
      } while (op != 6);
  
      return 0;
  }
  </code></pre>