title: How do i fix this error? Switch statement
body: <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  struct student
  {
      char name[30];
      char dob[30];
      int rollno;
      float percent;
      int sub[3];
      int total;
  };
  
  int main(void)
  {
      int i, n,a,c,*ptr;
      char ch;
      struct student *st;
      
      printf(&quot;Enter number of students data you want to enter:\n&quot;);
      scanf(&quot;%d&quot;,&amp;n);
  
      st=(struct student*) malloc(n * sizeof(struct student));
  
      if(st == NULL) 
      {
          printf(&quot;Error! memory not allocated.&quot;);
          exit(0);
      }
  
      for(i=1;i &lt;= n;i++)
      {
          printf(&quot;Enter name of student %d\n&quot;,(i));
          scanf(&quot;%s&quot;,&amp;(st+i)-&gt;name);
          printf(&quot;Enter Roll No of student %d\n&quot;,(i));
          scanf(&quot;%d&quot;,&amp;(st+i)-&gt;rollno);
          printf(&quot;Enter Date Of Birth of student %d\n&quot;,(i));
          scanf(&quot;%s&quot;,&amp;(st+i)-&gt;dob);
          printf(&quot;Enter marks for 3 subjects of student %d\n&quot;,(i));
          scanf(&quot;%d %d %d&quot;,&amp;(st+i)-&gt;sub[0],&amp;(st+i)-&gt;sub[1],&amp;(st+i)-&gt;sub[2]);
          (st+i)-&gt;total = ((st+i)-&gt;sub[0]+(st+i)-&gt;sub[1]+(st+i)-&gt;sub[2]);
          printf(&quot;Total Marks of student %d = %d\n\n&quot;,(i), (st+i)-&gt;total);
      }
      printf(&quot;\n&quot;);
  
      printf(&quot;\n&lt;1&gt;To display details of students\n&quot;);
      printf(&quot;\n&lt;2&gt;exit\n&quot;);
      printf(&quot;Enter your choice:\n&quot;);
      scanf(&quot;%c&quot;,&amp;ch);
  
      switch(ch)
      {
      case '1':
      {      
          for(i=1; i &lt;= n;i++)
          { 
              printf(&quot;\n%d.%s&quot;,(st+i)-&gt;rollno,(st+i)-&gt;name);
          }
  
          printf(&quot;\n Enter Roll no to display info of student&quot;);
          scanf(&quot;%d&quot;,&amp;a);
  
          {
              c=a;
              a=i;
              i=c;
  
          if((st+i)-&gt;sub[0]&lt;33||(st+i)-&gt;sub[1]&lt;33||(st+i)-&gt;sub[2]&lt;33)
          {   
              printf(&quot;\nName of student: %s&quot;,(st+i)-&gt;name);
              printf(&quot;\nRoll No of student: %d&quot;,(st+i)-&gt;rollno);
              printf(&quot;\nDate of Birth : %s&quot;,(st+i)-&gt;dob);
              printf(&quot;\nTotal of student: %d&quot;,(st+i)-&gt;total);
              printf(&quot;\nStudent Status fail&quot;);
              return 0;
          }
  
          printf(&quot;\nName of student: %s&quot;,(st+i)-&gt;name);
          printf(&quot;\nRoll No of student: %d&quot;,(st+i)-&gt;rollno);
          printf(&quot;\nDate of Birth : %s&quot;,(st+i)-&gt;dob);
          printf(&quot;\nTotal of student: %d&quot;,(st+i)-&gt;total);
  
          (st+i)-&gt;percent=((st+i)-&gt;total)/3;
  
          printf(&quot;\nPercent of Student = %f&quot;,(st+i)-&gt;percent);
  
          if((st+i)-&gt;percent&gt;=33)
          {
              printf(&quot;\nStudent status:- PASS\n&quot;);
          }
          else
              printf(&quot;\nStudent status:-FAIL\n&quot;);
  
          if((st+i)-&gt;percent&gt;=90)
              printf(&quot;Grade= A1\n&quot;);
          else if (80&lt;=(st+i)-&gt;percent)
              printf(&quot;Grade= A2\n&quot;);
          else if(70&lt;=(st+i)-&gt;percent)
              printf(&quot;Grade= B1\n&quot;);
          else if(60&lt;=(st+i)-&gt;percent)
              printf(&quot;Grade= B2\n&quot;);
          else if(50&lt;=(st+i)-&gt;percent)
              printf(&quot;Grade= C1\n&quot;);
          else if(40&lt;=(st+i)-&gt;percent)
              printf(&quot;Grade= C2\n&quot;);
          else if(33&lt;=(st+i)-&gt;percent)
              printf(&quot;Grade= D\n&quot;);
          else if((st+i)-&gt;percent&lt;33)
              printf(&quot;Grade= F\n&quot;);
          }
  
          break;
      }
  
      case '2':
      {
          return 0;
      }
  
      default:
          printf(&quot;Invalid! Try again...\n&quot;);
      }
  
      free(st);
      return 0;
  }
  </code></pre>
  <p>I want my program to take input of various details of students and display them when I enter the roll no. of student. However,
  the switch statement is not executing; the program just exits after taking input.
  I checked syntax, but it's correct I don't know what the issue is.
  If I could get a hint about the issue it would be great.</p>