-1

I try to get and print some structure values. Here is my loop block:

for(int i = 0; i < COURSE_LIMIT; i++)
   {
       printf("Enter the course name: ");

       fgets(studentProfile.courses[i].course_name, COURSE_NAME, stdin);              
       printf("Enter the quota: ");
       scanf("%d", studentProfile.courses[i].quota);


   }//get loop

   for(int j = 0; j < COURSE_LIMIT; j++)
   {
       printf("\nyour %d. course name is: %s",j+1, studentProfile.courses[j].course_name);
       printf("Your %c. course quota is: %d", j + 1, studentProfile.courses[j].quota);
   }//print loop

When I try to do them sepereately it's okay. But when I try to get input from same loop I got segmentation fault..

1 Answers1

-1

scanf takes its arguments as a pointer to the value you read from stdin. Check what you read in from:

scanf("%d", studentProfile.courses[i].quota);

For a general int i:

scanf("%d", &i);