我正在为某个任务编写程序,我有一个名为Course.h的头文件,在其中编写了这个结构:
typedef struct Course{
int numCourse;
char nameofCourse[MAX_NAME_OF_COURSE];
int maxStudents;
int currentStudents;
Grades studentsGrades[MAX_COURSES];
}Course;
之后, 我编写了一个从Course类型返回c1的函数:
Course getNewCourse(){
Course c1;
int i, num=0;
int st_now=0; /*for currently student in the course*/
char temp1[MAX_NAME_OF_COURSE]; /*for course name*/
char temp2[FIVE]; /*for student id*/
temp1[0] = '\0'; /*clean the string befor use it*/
temp2[0] = '\0';
printf("Please enter the course number (FIVE digits):\n"); /*add the course number*/
clear_buffer();
while(scanf("%d", &num)){
if(cheakIfNumCourseIsProper(num)==1){
c1.numCourse = num;
break;
}
printf("Error! Please try again:\n");
}
printf("Please enter the course name (FIVE digits):\n"); /*add the course name*/
clear_buffer();
while(scanf("%s", temp1)){
if(checkNameCourse(temp1)==1){
strcpy(c1.nameofCourse,temp1);
break;
}
printf("Error! Please try again:\n");
}
printf("Please enter maximum of students in the course: (between ZERO-MAX_COURSES):\n"); /*max students*/
clear_buffer();
num=0;
while(scanf("%d", &num)){
if(checkMaxNumofCoursesYear(num)==1){
c1.maxStudents = num;
break;
}
printf("Error! Please try again:\n");
}
printf("Please enter the number of students currently in the course: (between ZERO-THOUSAND):\n"); /*students in course*/
clear_buffer();
while(scanf("%d", &st_now)){
if(checkNumStudentInCourse(st_now)==1){
c1.currentStudents = st_now;
break;
}
printf("Error! Please try again:\n");
}
printf("Please write student id and his grades:\n"); /*students grades array*/
clear_buffer();
for(i=0;i<st_now;i++)
{
c1.studentsGrades[i].id_test=getStudentId();
c1.studentsGrades[i].examA=getGradeExam();
c1.studentsGrades[i].examB=getGradeExam();
}
return c1;
}
如您所见,该函数返回c1。 (该函数在“ inputs.c”下,我包含了“ course.h” ofc)
但是gcc编译器给我这个错误:
inputs.h:13:1:错误:类型名称未知的“课程”;你的意思是“双”吗? 课程getNewCourse(); ^ ~~~~~
我的代码怎么了?
编辑: 这是inputs.h标头:
#ifndef INPUTS_H_
#define INPUTS_H_
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include "course.h"
#include "student.h"
#include "common.h"
#include "checks.h"
/*inputs courses:*/
int getNumofMaxCourses();
Course getNewCourse();
char * getCouseNum();
double getCoursetoAdd();
int getCoursetoDelete();
/*inputs students:*/
int getGradeExam();
int getMaxNumberOfStudets();
Student getNewStudent();
char* getStudentTodelete();
char * getStudentId();
/*inputs common:*/
int getCourseNum();
char* getCourseName();
#endif