title: c++ memory leak on my data structure
body: <p>So I've graduated from learning C and now learning C++. From what I understand C and C++ are similar in variety of ways so I'm trying to re-write my past C project files into C++. However I keep getting a memory leak when I try to print out my information. Can someone tell me why I am getting a memory leak in my code.</p>
  
  <h2>struct.h</h2>
  
  <pre><code>typedef struct student_info {
      char last[10];
      char first[10];
      int student_id;
      int count_student;
  } student;
  
  typedef struct course_info {
      char name[10];
      int course_id;
      int count_course;
      student *students;
  } course;
  
  typedef struct gradebook_info {
      course *courses;
  } gradebook;
  </code></pre>
  
  <h2>function.c</h2>
  
  <pre><code>void new_course(gradebook *info) {
      int i, loop=0;
  
      cout &lt;&lt; "Enter Number of Courses " ;
      cin &gt;&gt; loop;
  
      for(i=0; i&lt;loop; i++) {
  
          cout &lt;&lt; "Enter Course ID ";
          cin &gt;&gt; info-&gt;courses[info-&gt;courses-&gt;count_course].course_id;
  
          cout &lt;&lt; "Enter Course Name ";
          cin &gt;&gt; info-&gt;courses[info-&gt;courses-&gt;count_course].name;
  
          info-&gt;courses-&gt;count_course++;
  
      }
  }
  
  void new_student(gradebook *info) {
      int i, loop=0;
  
      cout &lt;&lt; "Enter Number of Students " ;
      cin &gt;&gt; loop;
  
      for(i=0; i&lt;loop; i++) {
  
          cout &lt;&lt; "Enter Student ID ";
          cin &gt;&gt; info-&gt;courses-&gt;students[info-&gt;courses-&gt;students-&gt;count_student].student_id;
  
          cout &lt;&lt; "Enter Last Name ";
          cin &gt;&gt; info-&gt;courses-&gt;students[info-&gt;courses-&gt;students-&gt;count_student].last;
  
          cout &lt;&lt; "Enter First Name ";
          cin &gt;&gt; info-&gt;courses-&gt;students[info-&gt;courses-&gt;students-&gt;count_student].first;
  
          info-&gt;courses-&gt;students-&gt;count_student++;
      }
  }
  
  void printCourse(gradebook *info) {
      int i;
  
      cout &lt;&lt; "Course ID\tCourse Name\t" &lt;&lt; endl;
  
      for(i=0; i&lt;info-&gt;courses-&gt;count_course; i++) {
  
          cout &lt;&lt; info-&gt;courses[i].course_id &lt;&lt; "\t\t";
          cout &lt;&lt; info-&gt;courses[i].name &lt;&lt; endl;
      }
  }
  
  void printStudent(gradebook *info) {
      int i; 
  
      cout &lt;&lt; "Student ID\tLast Name\tFirst Name\t" &lt;&lt; endl;
  
      for(i=0; i&lt;info-&gt;courses-&gt;students-&gt;count_student; i++) {
  
          cout &lt;&lt; info-&gt;courses-&gt;students[i].student_id &lt;&lt; "\t\t";
          cout &lt;&lt; info-&gt;courses-&gt;students[i].last &lt;&lt; "\t\t";
          cout &lt;&lt; info-&gt;courses-&gt;students[i].first &lt;&lt; endl;
      }
  }
  </code></pre>
  
  <ul>
  <li>When I run <code>new_course()</code> function it works.</li>
  <li>I run my <code>printCourse()</code> function it works.</li>
  <li>I run <code>new_student()</code> function it works.</li>
  <li>When I run <code>printStudent()</code> function it works.</li>
  <li>Then I try to run <code>printCourse()</code> function again and when <code>i=2</code>, I get some information from my struct student.</li>
  </ul>
  
  <p>I can't figure it out. Any help is appreciated.</p>
  
  <h2>main.c</h2>
  
  <pre><code>gradebook *info = new gradebook; //allocate memory
  
  do {
      main_menu();
  
      int option=0;
  
      switch(option) {
          case 1: new_course(info);
              break;
          case 2: new_student(info);
              break;
          case 3: printCourse(info);
              break;
          case 4: printStudent(info);
              break;
      }
  }while(option &lt; 13);
  
  delete(info);
  </code></pre>