title: C: Array of Structs (Input into int array within array of structs)
body: <p>Hi I have to create a database that stores students number, name and also stores an array of course marks (1-N) in C Programming Language.</p>
  
  <p>Everything worked until I started coding for the array of course marks. Then every time I compiled the code it kept crashing as soon as it asked to input the course marks.</p>
  
  <p>Can you please tell me where I'm going wrong in my programming for this task? I have attached it to this message. </p>
  
  <p>The program worked for inputting the name, student number, however I could not get the program to input array of marks. I have asked how many course marks to be entered and then used a for loop within the "void insert(void)" function to keep inputting the course marks into the array *marks. I am referring specifically to lines 24 to 30 in my programming code.</p>
  
  <p>Always at this point the program kept crashing and I could not proceed further to enter more names  or print the stored student details.</p>
  
  <p><strong>I think there is a problem with this part:</strong></p>
  
  <pre><code>for (i= 0; i &lt; num_marks; i++)
  {
      printf("Enter Course Mark: \n");
      scanf("%d", &amp;(list[num_students].marks[num_marks]));
  }
  </code></pre>
  
  <p><strong>Anyway here is the full code:</strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  struct student{
      int number;
      char name[10];
      int marks[5];
  };
  struct student list[10];
  
  int num_students = 0;
  int num_marks = 0;
  int *p;
  
  void insert(void)
  {
      int student_number;
      int i;
      printf("Enter number: \n");
      scanf("%d", &amp;list[num_students].number);
      printf("Enter NAME: \n");
      scanf("%s", &amp;list[num_students].name);
      printf("Enter NO of courses: \n");
      scanf("%d", num_marks);
      for (i= 0; i &lt; num_marks; i++)
      {
          printf("Enter Course Mark: \n" );
          scanf("%d", &amp;(list[num_students].marks[num_marks]));
      }
      num_students++; // HOW DO WE INPUT ARRAY MARKS??? MARK1: , MARK2: , MARK3 ,
  }
  
  void printtest(void)
  {
      int i;
      for (i=0; i &lt; num_students; i++)
      {
          printf("Name: \n");
          puts(list[i].name);
          printf("Number: %d \n", list[i].number);
          printf("Mark: %d /100 \n", list[i].marks);
          printf("\n");
      }
  }
  
  int main(void)
  {
      int code;
      int opt1;
      int courses, i, k, j, counter;
      for (;;){
          printf("Enter operation code: \n");
          printf("(1) ADD NEW STUDENT DETAILS: \n");
          printf("(2) DISPLAY REPORT OF ALL STUDENTS: \n");
          scanf(" %d", &amp;code);
          switch (code){
              case 1 :
                  insert();
                  break;
              case 2 :
                  printtest();
                  break;
              default:
                  printf("Illegal code\n");
                  printf("\n");
          }
      }
  }
  </code></pre>