struct student * create();
时间: 2024-01-21 17:17:08 浏览: 25
这是一个函数原型,函数名为 create,返回值类型为指向 struct student 类型的指针。
这个函数可以用来创建一个链表节点,其中 struct student 是一个自定义的结构体类型,可能长这样:
```c
struct student {
int id;
char name[20];
float score;
struct student *next;
};
```
具体实现可以参考以下代码:
```c
struct student * create() {
struct student *head, *p, *q;
head = NULL;
q = NULL;
int id;
char name[20];
float score;
while (1) {
printf("请输入学生信息(ID为0时结束):\n");
scanf("%d", &id);
if (id == 0) break;
p = (struct student *) malloc(sizeof(struct student));
p->id = id;
scanf("%s%f", name, &score);
strcpy(p->name, name);
p->score = score;
if (head == NULL) head = p;
else q->next = p;
q = p;
}
if (head != NULL) q->next = NULL;
return head;
}
```
这个函数可以通过循环读入用户输入的学生信息,创建链表节点,最后返回链表头指针。可以在 main 函数中调用这个函数来创建链表。
相关推荐
![application/octet-stream](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![c](https://img-home.csdnimg.cn/images/20210720083646.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)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)