#include<stdio.h>
#include <malloc.h>
#include <string.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;
void insertTail(PolyNode* L, long int num , char *name , char sex, double chinese, double math, double english) {
PolyNode* p = L->next;
PolyNode* s,* pre = L;
s = (PolyNode*)malloc(sizeof(PolyNode));
while (p != NULL) {
pre = p;
p = p->next;
}
s->num = num;
strcpy(s->name,name);
s->sex[0] = sex;
s->chinese = chinese;
s->math = math;
s->english = english;
s->next = pre->next;
pre->next = s;
}
PolyNode* createList() {
PolyNode* L;
L = (PolyNode*)malloc(sizeof(PolyNode));
L->next = NULL;
return L;
}
void printList(PolyNode* L) {
PolyNode* p = L->next;
while (p != NULL) {
printf("0%d %s %c %.1lf %.1lf %.1lf\n", p->num,p->name, p->sex[0], p->chinese, p->math, p->english);
p = p->next;
}
}
void findList(PolyNode* L,long int num) {
PolyNode* p = L->next,* pre = L;
while (p->num != num && p != NULL) {
pre = p;
p = p->next;
}
if (pre->num == num) {
printf("0%d %s %c %.1lf %.1lf %.1lf\n", pre->num, pre->name, pre->sex[0], pre->chinese, pre->math, pre->english);
}
else {
printf("Failed\n");
}
}
int main() {
char a[10],name[20],sex[2];
long int num;
double chinese, math, english;
PolyNode* L = createList();
PolyNode* head = L;
while (1) {
scanf("%s", a);
if (a[0] == 'I') {
scanf("%d %s %c %lf %lf %lf", &num, name, &sex[0], &chinese, &math, &english);
insertTail(L,num,name,sex[0], chinese, math, english);
printf("Insert:\n");
printList(L);
L = L->next;
}
if (a[0] == 'Q' || a[0] == 'E') {
printf("Good bye!\n");
break;
}
if (a[0] == 'L') {
printf("List:\n");
printList(head);
}
if (a[0] == 'F') {
scanf("%d", &num);
printf("Find:");
findList(head,num);
}
}
}
你调试一下,看看因为什么原因退出,当时相关变量的值是多少