#include<stdio.h>
#include <malloc.h>
typedef struct Node
{
char instruct[10];
long int num; //学号
char name[20]; //姓名
char sex[2]; //性别
double chinese; //语文
double math; //数学
double english; //英语
struct Node* next;
} PolyNode, * PolyList;
PolyList createList(){
PolyList L;
L = (PolyList)malloc(sizeof(PolyList));
L->next = NULL;
return L;
}
void insertTail(PolyList L,double math) {
Node* p = L->next;
PolyList s,pre = L;
s = (PolyList)malloc(sizeof(PolyList));
while (p != NULL) {
pre = p;
p = p->next;
}
s->math = math;
pre->next = s;
}
void printList(PolyList L) {
Node* p = L->next;
while (p != NULL) {
printf("%.1lf ",p->math);
p = p->next;
}
}
int main() {
char a[10];
PolyList L;
L = (PolyList)malloc(sizeof(PolyList));
L->next = NULL;
insertTail(L, 10.2);
printList(L);
}
L = (PolyList)malloc(sizeof(PolyList));
改为
L = (PolyList)malloc(sizeof(PolyNode));
你要申请的是PolyNode结构体大小空间,但PolyList是个指针,只能申请4个字节空间
17、26行都是这样