小白新学链表 想用函数来表达一下 在函数返回值的地方遇到麻烦 请大佬们帮助
typedef struct student {
char name[10];
int num;
struct scan {
int speach;
int read;
int write;
int hear;
}SCAN;
struct student *next;
}STUDENT;
用函数创建一个链表后 想返回头节点 如何以STUDENT* 返回函数值
STUDENT* creatlink() {
char name[10],*t;
int i, n, num, s, r, w, h;
STUDENT *head, *p, *q;
printf("输入要录入的人数:");
scanf("%d", &n);
printf("请依次录入学生的学号 姓名 及听说读写的分数");
head = NULL;
q = NULL;
for (i = 0; i < n; i++) {
p = (STUDENT *)malloc(sizeof(STUDENT));
scanf("%d%s%d%d%d%d", &num, name, &s, &r, &w, &h);
p->num = num;
strcpy(p->name,name);
p->SCAN.speach = s;
p->SCAN.hear = h;
p->SCAN.read = r;
p->SCAN.write = w;
if (head == NULL) head = p;
else q->next = p;
q = p;
}
return *head;
}
编译时在
return head; *号上
说 不存在从 STUDENT 到STUDENT 的适当转换函数
然后我删掉返回值上的*(return *head;) 后 输出的函数又不能用了
求大佬帮助 全部代码在下面
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct student {
char name[10];
int num;
struct scan {
int speach;
int read;
int write;
int hear;
}SCAN;
struct student *next;
}STUDENT;
STUDENT* creatlink() {
char name[10],*t;
int i, n, num, s, r, w, h;
STUDENT *head, *p, *q;
printf("输入要录入的人数:");
scanf("%d", &n);
printf("请依次录入学生的学号 姓名 及听说读写的分数");
head = NULL;
q = NULL;
for (i = 0; i < n; i++) {
p = (STUDENT *)malloc(sizeof(STUDENT));
scanf("%d%s%d%d%d%d", &num, name, &s, &r, &w, &h);
p->num = num;
strcpy(p->name,name);
p->SCAN.speach = s;
p->SCAN.hear = h;
p->SCAN.read = r;
p->SCAN.write = w;
if (head == NULL) head = p;
else q->next = p;
q = p;
}
return *head;
}
void putlink(STUDENT *HEAD) {
STUDENT *t;
t = HEAD;
while (t != NULL) {
printf("%d\t%s\t听%d,说%d,读%d,写%d", t->num, t->name, t->SCAN.hear, t->SCAN.speach, t->SCAN.read, t->SCAN.write);
t = t + 1;
}
}
int main() {
STUDENT *HEAD;
HEAD = NULL;
putlink(creatlink());
return 0;
}