Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 打印结构值故障_C_Arrays_Loops_Struct_Nested - Fatal编程技术网

C 打印结构值故障

C 打印结构值故障,c,arrays,loops,struct,nested,C,Arrays,Loops,Struct,Nested,我尝试获取并打印一些结构值。这是我的循环块: 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("%

我尝试获取并打印一些结构值。这是我的循环块:

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
for(int i=0;i

当我试着分开做的时候,没关系。但当我试图从同一个循环中获取输入时,我遇到了分段错误

scanf将其参数作为指向从stdin读取的值的指针。 检查您从以下位置阅读的内容:

scanf("%d", studentProfile.courses[i].quota);
对于一般int i:

scanf("%d", &i);

scanf(“%d”,studentProfile.courses[i].quota)->
scanf(“%d”和studentProfile.courses[i].quota)总是,总是,总是。。。检查scanf返回的值