title: When the main() function is called back the program is terminated. Is there a way I can fix this?
body: <p>I have to write a c program to manage the reservations. When I call back the main function the program gets terminated without continuing. How can I fix this error? ( I haven't written the whole program)</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  int main(){
   int i, j, day, x;
   char session[10];
   int array[2][5] = {{0,0,1,0,1},{1,1,0,0,0}};
   char response,ans,choice;
  
   printf(&quot;**************** WELCOME TO NAT RESERVATION SYSTEM ****************&quot;);
  
   printf(&quot;\n\nCHOOSE WHAT TO DO&quot;);
  
   printf(&quot;\n\n\t\tA.\t\tBOOK THE THEATER&quot;);
   printf(&quot;\n\t\tB.\t\tCHECK RESERRVATIONS&quot;);
   printf(&quot;\n\t\tC.\t\tREMOVE RESERVATIONS&quot;);
   printf(&quot;\n\t\tD.\t\tCALCULATE INCOME&quot;);
   printf(&quot;\n\t\tE.\t\tEXIT&quot;);
  
   printf(&quot;\n\nYOUR RESPONSE\t\t:  &quot;);
   scanf(&quot;%c&quot;,&amp;response);
  
  
   switch (response){
     case 'A': printf(&quot;\n\nBOOK THE THEATER&quot;); break;
     case 'B': printf(&quot;\n\nCHECK RESERRVATIONS&quot;); break;
     case 'C': printf(&quot;\n\nREMOVE RESERVATIONS&quot;); break;
     case 'D': printf(&quot;\n\nCALCULATE INCOME&quot;); break;
     case 'E': printf(&quot;\n\nEXIT&quot;); break;
   }
  
   if (response == 'A'){
  
    printf(&quot;\n\nCHOOSE A DAY   :   &quot;);
    scanf(&quot;%d&quot;,&amp;day);
    j = day -1;
  
    printf(&quot;YOUR SESSION     :   &quot;);
    scanf(&quot;%c&quot;,session);
    fgets(session,10,stdin);
  
    if(strcmp(session,&quot;MORNING&quot;)){
      i = 0;
    }else if(strcmp(session,&quot;AFTERNOON&quot;)){
      i = 1;
    }else{
      printf(&quot;PLEASE ENTER MORNING OR AFTERNOON&quot;);
    }
  
    if(array[i][j] == 0){
      printf(&quot;\n\nTHE SESSION IS AVAILABLE.\nDO YOU WANT TO CONFIRM THE BOOKING?(Y/N)   :   &quot;);
      scanf(&quot;%c&quot;,&amp;ans);
  </code></pre>
  <p>I want to direct the program to print the main menu. So I called back the main() function here.</p>
  <pre><code>    if(ans == 'Y' || ans == 'y'){
        array[i][j] = 1;
        printf(&quot;\nYOUR BOOKING WAS SUCCESSFUL!\n\n&quot;);
        main();
      }
    }else if(array[i][j] == 1){
      printf(&quot;\n\nTHE SESSION IS NOT AVAILABLE.&quot;);
      printf(&quot;DO YOU WANT TO TRY ANOTHER SESSION?(Y/N):  &quot;);
      scanf(&quot;%c&quot;,&amp;ans);
  
      if(ans == 'Y' || ans == 'y'){
        main();
      }else if(ans == 'N' || ans == 'n'){
        printf(&quot;THANK YOU! HAVE A NICE DAY!&quot;);
        exit(0);
      }
    }  
   }
  }
  </code></pre>
  <p>I tried to use a while loop. I don't know what to put inside the brackets. Please help me. I'm new to C programming as I learned most of them online.</p>
  <pre><code>while(1){
   printf(&quot;**************** WELCOME TO NAT RESERVATION SYSTEM ****************&quot;);
  
  
  printf(&quot;\n\nCHOOSE WHAT TO DO&quot;);
  
  printf(&quot;\n\n\t\tA.\t\tBOOK THE THEATER&quot;);
  printf(&quot;\n\t\tB.\t\tCHECK RESERRVATIONS&quot;);
  printf(&quot;\n\t\tC.\t\tREMOVE RESERVATIONS&quot;);
  printf(&quot;\n\t\tD.\t\tCALCULATE INCOME&quot;);
  printf(&quot;\n\t\tE.\t\tEXIT&quot;);
  
  printf(&quot;\n\nYOUR RESPONSE\t\t:  &quot;);
  scanf(&quot;%c&quot;,&amp;response);
  
  
  switch (response){
    case 'A': printf(&quot;\n\nBOOK THE THEATER&quot;); break;
    case 'B': printf(&quot;\n\nCHECK RESERRVATIONS&quot;); break;
    case 'C': printf(&quot;\n\nREMOVE RESERVATIONS&quot;); break;
    case 'D': printf(&quot;\n\nCALCULATE INCOME&quot;); break;
    case 'E': printf(&quot;\n\nEXIT&quot;); break;
  }
  
  if (response == 'A'){
  
    printf(&quot;\n\nCHOOSE A DAY   :   &quot;);
    scanf(&quot;%d&quot;,&amp;day);
    j = day -1;
  
    printf(&quot;YOUR SESSION     :   &quot;);
    scanf(&quot;%c&quot;,session);
    fgets(session,10,stdin);
  
    if(strcmp(session,&quot;MORNING&quot;)){
      i = 0;
    }else if(strcmp(session,&quot;AFTERNOON&quot;)){
      i = 1;
    }else{
      printf(&quot;PLEASE ENTER MORNING OR AFTERNOON&quot;);
    }
  
    if(array[i][j] == 0){
      printf(&quot;\n\nTHE SESSION IS AVAILABLE.\nDO YOU WANT TO CONFIRM THE BOOKING?(Y/N)   :   &quot;);
      scanf(&quot;%c&quot;,&amp;ans);
  
      if(ans == 'Y' || ans == 'y'){
        array[i][j] = 1;
        printf(&quot;\nYOUR BOOKING WAS SUCCESSFUL!\n\n&quot;);
        continue;
        main();
      }
    }
    if(array[i][j] == 1){
      printf(&quot;\n\nTHE SESSION IS NOT AVAILABLE.&quot;);
      printf(&quot;DO YOU WANT TO TRY ANOTHER SESSION?(Y/N):  &quot;);
      scanf(&quot;%c&quot;,&amp;ans);
  
      if(ans == 'Y' || ans == 'y'){
        continue;
        main();
      }else if(ans == 'N' || ans == 'n'){
        printf(&quot;THANK YOU! HAVE A NICE DAY!&quot;);
        exit(0);
      }
    }  
  }
  </code></pre>