C语言编程链表基础问题(哪里错了呢?)

来源:百度知道 编辑:UC知道 时间:2024/06/17 19:43:46
设有N名学生,N由键盘输入,他们可以根据自己的实际情况选修不相同的课程(设课程总数M=3)。要求:

为每门课程建立一个选课链表,并在显示器上显示每个链表生成的过程;
链表结点顺序按学号从小到大排列,当有学生选课时,链表做插入操作,当有学生不选该课程时,链表做删除操作,并要在显示器上显示这些操作过程。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct student
{
long stuID;
char name[20];
int course;
float grade;
struct student *next;
};

typedef struct student stu;

stu *insertlist(int num,char name[20],stu *head)
{

char sub[10];
if (head->course = 1) strcpy(sub,"Math");
if (head->course = 2) strcpy(sub,"English");
if (head->course = 3) strcpy(sub,"Chinese");

while(head->next!=NULL)
head = head->next;

if(head->next==NULL)
head->stuID = num;
strcpy(head->name, name);
if(head->course = 1) head->next-

这是我今天写的一部分代码,领会精神。建议做链表时先画图分析一下数据结构,你可以先看一下别人的代码,先分析别人的代码,然后试试自己编一个简单的(没有参照的编程)。看一下数据结构方面的书会对你学习链表有很大的帮助。记着要勤加练习哦!
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#define MAX 20

struct Student
{
char Name[MAX];
int Math;
int Chinese;
int English;
int TotalNumber;
struct Student *next;
};

struct Student *InsertInformation(struct Student *head)
{
struct Student *temp = NULL , *pr = head;
struct Student *NewInfor = (struct Student *)malloc(sizeof(struct Student));
NewInfor->next = NULL;
if (NewInfor == NULL)
{
printf("No enough memory to alloc!\n");
}
printf("Please input the name of the student you want to input:\n");
scanf("%s",&NewInfor->Name[MAX]);
printf("Please input the math mark of the student:\