int main() { struct chexinxi *addchexinxi(); struct chexinxi *head; void xianshi(head); head=addchexinxi(); xianshi(head); return 0; }为什么错了
时间: 2024-02-17 22:02:09 浏览: 21
这个程序存在一些语法错误,具体错误如下:
1. 函数声明不应该在 main 函数中,应该在 main 函数之前或者使用头文件声明。
2. void xianshi(head); 这句话是函数声明,应该改为函数调用 xianshi(head);
3. 在调用函数时,应该先定义一个函数指针,再将函数指针赋值给函数指针变量,最后通过函数指针变量调用函数。
下面是修改后的程序:
```
#include <stdio.h>
#include <stdlib.h>
struct chexinxi* addchexinxi();
void xianshi(struct chexinxi* head);
int main() {
struct chexinxi* head = addchexinxi();
xianshi(head);
return 0;
}
struct chexinxi* addchexinxi() {
struct chexinxi* p = (struct chexinxi*)malloc(sizeof(struct chexinxi));
// 添加车辆信息的代码
return p;
}
void xianshi(struct chexinxi* head) {
// 输出车辆信息的代码
}
```
上面的程序中,我们将函数声明放在了 main 函数之前,并且修改了 xianshi 函数的声明和调用方式。同时,我们在 addchexinxi 函数中添加了创建结构体并返回指针的代码,并在 main 函数中通过指针调用 xianshi 函数来输出车辆信息。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)