title: gets() function not working properly in C++
body: <p>I wrote two programs with a common class and different main functions.</p>
  
  <p>These are the codes:</p>
  
  <p><strong>COMMON CLASS</strong></p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;cstring&gt;
  #include&lt;cstdio&gt;
  
  using namespace std;
  
  class student
  {
    char *name;
    int *marks,avg;
  public:
    student()
     {
      int n,i,tot;
      tot=0;
      name=new char[40];
      cout&lt;&lt;"enter the name of the student";
      gets(name);
      cout&lt;&lt;"enter the number of subjects";
      cin&gt;&gt;n;
      marks=new int[n];
      cout&lt;&lt;"MARKS"&lt;&lt;endl;
      for(i=0;i&lt;n;i++)
       {
          cout&lt;&lt;"enter the marks in subject:"&lt;&lt;i+1&lt;&lt;" ";
          cin&gt;&gt;*(marks+i);
          tot=tot+(*(marks+i));
       }
      avg=tot/n;
     }
  
      ~student()
      {
          delete[] marks;
      }
  
      void display()
      {
          cout&lt;&lt;endl&lt;&lt;"name of the student: "&lt;&lt;name&lt;&lt;endl;
          cout&lt;&lt;"the average of the student: "&lt;&lt;avg&lt;&lt;endl;
      }
  
  }; 
  </code></pre>
  
  <p><strong>FIRST MAIN FUNCTION</strong></p>
  
  <pre><code>int main()
  {
   int n,i;
   cout&lt;&lt;"enter the number of students";
   cin&gt;&gt;n;
   student *ob=new student[n];
  
    for(i=0;i&lt;n;i++)
     {
      (ob+i)-&gt;display();
     }
   return 0;
  }
  </code></pre>
  
  <p><strong>SECOND MAIN FUNCTION</strong></p>
  
  <pre><code> int main()
   {
    student o;
    o.display();
    return 0;
   }
  </code></pre>
  
  <p>In the program with the first main function,the gets() function in the constructor of the class student is not working at all but with the second main function it is working fine.</p>
  
  <p>Can somebody please help me to run the first program properly using gets().</p>