2020-02-19 17:53

# 如何返回结构体指针？

``````typedef struct student {
char name[10];
int num;
struct scan {
int speach;
int write;
int hear;
}SCAN;
struct student *next;
}STUDENT;
``````

``````STUDENT* creatlink() {
char name[10],*t;
int i, n, num, s, r, w, h;
printf("输入要录入的人数：");
scanf("%d", &n);
printf("请依次录入学生的学号 姓名 及听说读写的分数");
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.write = w;
else q->next = p;
q = p;
}

}
``````

``````#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 write;
int hear;
}SCAN;
struct student *next;
}STUDENT;
char name[10],*t;
int i, n, num, s, r, w, h;
printf("输入要录入的人数：");
scanf("%d", &n);
printf("请依次录入学生的学号 姓名 及听说读写的分数");
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.write = w;
else q->next = p;
q = p;
}

}

STUDENT *t;
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() {

return 0;
}

``````
• 写回答
• 好问题 提建议
• 关注问题
• 收藏
• 邀请回答

#### 1条回答默认 最新

• sun_xf1 2020-02-19 20:01
已采纳

char name[10],*t;
int i, n, num, s, r, w, h;
printf("输入要录入的人数：");
scanf("%d", &n);
printf("请依次录入学生的学号 姓名 及听说读写的分数");
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.write = w;

``````    if(q != NULL)
q->next = p;
q = p;
}