// 创建一个新的校友信息节点 Alumni *create_alumni(char *name, int grad_year, char *phone) { Alumni *alumni = (Alumni *)malloc(sizeof(Alumni)); strcpy(alumni->name, name); alumni->grad_year = grad_year; strcpy(alumni->phone, phone); alumni->dept = NULL; return alumni; } // 创建一个新的院系节点 Department *create_department(char *name) { Department *dept = (Department *)malloc(sizeof(Department)); strcpy(dept->name, name); dept->alumni_list = NULL; dept->left = NULL; dept->right = NULL; return dept; }这段代码显示initializing argument 1 of 'Alumni* create_alumni(char*, int, char*)'和initializing argument 1 of 'Department* create_department(char*)'这两个错误,请改正
时间: 2024-02-13 08:04:19 浏览: 69
错误提示表明函数调用时传入的第一个参数类型与函数定义时的类型不匹配。具体来说,函数声明中第一个参数需要的是指向字符数组的指针,而调用时传入的是字符数组本身。
为了解决这个问题,我们需要修改函数调用时的参数。将需要传入的字符数组改为指向字符数组的指针即可。修改后的代码如下:
```
// 创建一个新的校友信息节点
Alumni *create_alumni(char *name, int grad_year, char *phone) {
Alumni *alumni = (Alumni *)malloc(sizeof(Alumni));
strcpy(alumni->name, name);
alumni->grad_year = grad_year;
strcpy(alumni->phone, phone);
alumni->dept = NULL;
return alumni;
}
// 创建一个新的院系节点
Department *create_department(char *name) {
Department *dept = (Department *)malloc(sizeof(Department));
strcpy(dept->name, name);
dept->alumni_list = NULL;
dept->left = NULL;
dept->right = NULL;
return dept;
}
int main() {
// 修改调用参数为指向字符数组的指针
Alumni *alumni = create_alumni("张三", 2021, "1234567890");
Department *dept = create_department("计算机科学与技术");
return 0;
}
```
阅读全文