链表插入功能



大家好,

我尝试用链表来准备一个学生信息系统。我创建了一个名为course的结构。用于插入过程;我将在函数main中调用void insertCourse(CourseNodePtr* cr, char* code)。当我编译时,我看到了这些错误;"insertCourse"参数2的类型不兼容。函数insertCourse的参数太少。有人对此发表评论吗?多谢. .

/* Function Prototypes */
void insertCourse(CourseNodePtr* cr, char* code);
/* Main func starts here */
int main(void)
Course course_code; 

switch (choice) {
             case 1: 
                  insertCourse(&startPtr, course_code);
                  break;

/* Insert course function  */
void insertCourse(CourseNodePtr* cr, char* code)
{
CourseNodePtr newPtr;   /* New node pointer */
CourseNodePtr previousPtr;   /* previous node pointer in list */
CourseNodePtr currentPtr;    /* current node pointer in list */
newPtr = malloc( sizeof(Course) );   /* memory allocation for new node */
if (newPtr != NULL) {
           printf("Pls enter the code number of the course.n");
           scanf("%s", &(newPtr->code));
           printf("Pls enter the course name.n"); 
           scanf("%s", &(newPtr->name));
           printf("Pls enter the instructor name.n"); 
           scanf("%s", &(newPtr->instructor));
           printf("Pls enter the term; Spring or Fall.n"); 
           scanf("%s", &(newPtr->term));
           printf("Pls enter the year.n"); 
           scanf("%s", &(newPtr->year));
           newPtr->coursePtr = NULL; 
           previousPtr = NULL; 
           currentPtr = *cr; 
           while ((currentPtr != NULL)  && ( code  > currentPtr->code)) {
                 previousPtr = currentPtr; 
                 currentPtr = currentPtr->coursePtr; 
           }  /* End While */
           if ( previousPtr == NULL ) {
                newPtr->coursePtr = *cr; 
                *cr = newPtr; 
           }   /* End if */
           else {
                previousPtr->coursePtr = newPtr; 
                newPtr->coursePtr = currentPtr; 
           }  /* End else */
    } /* End if */
    else {
         printf( " %c could not be inserted. Memory not enough...n", code); 
    }  /* End else */
} /* End function insert */                    

insertCourse的第二个参数期望类型为*char,而您传递的类型为Course

insertCourse(&startPtr, course_code);
------------------------^ here

您将course_code定义为Course

Course course_code; 

调用insertCourse()

insertCourse(&startPtr, course_code);

但是参数必须是CourseNodePtr*char*

void insertCourse(CourseNodePtr* cr, char* code)

传递的第二个参数类型不正确。必须是Course

void insertCourse(CourseNodePtr* cr, Course code)

相关内容

  • 没有找到相关文章

最新更新