问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
#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);
}